From patchwork Fri Dec 17 10:57:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 12696624 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 432B8C433EF for ; Fri, 17 Dec 2021 11:00:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QJmN8Ldk+ekOYqv4bkBDmowQR8PvDZ6I83i5DJRX4/I=; b=dvJLPyaNDlYkJK ZYk0eRlsgcj0UHAJZNyIXYCwmz6aeh9mmgkT63AOxPnJvKm1MVBT0kwG+tnY6ORJ/75VIFnvJZBhm LEhOnaIRvZXgUaL+aAJWBJXzeelfpDWERpno/dguQXeIfKag6AD/d62qspSAhXefXHnF6EMowm/rZ gCCUW825c9ZNZhohR5QKn2UYZDAAfxB7DQjIL5Mz6wErNWh3iyv2TYb4zaJW2HjUW1QqPcaVlzkku k+uQKgadk5Mvjo+4/+qOmADjSL3d8HPHMHBRqhGINi3qvSMzfiAic+WNQ/aPxXEmGA1HXLrWImK9z Rf/H8cOGKdxURh7aVTww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1myAwj-009dWO-PC; Fri, 17 Dec 2021 10:58:42 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1myAwB-009dN4-44 for linux-arm-kernel@lists.infradead.org; Fri, 17 Dec 2021 10:58:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639738684; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vfMj5Cdv9ABQA5uXGp3mACXyYa8FBWK9SwauD15vTUk=; b=ck0e5uLBsBnT4do2DjKkBRRKPT+OiGACrXubvpVx7IxjW3kCRKLvd9XOoyJfwRL+qnyihF vWc5DEUrNDsYbnoYHHc5KdS+J4nDznIBzqSTv7/H16aaBVKAx9fzV8Ic1DXVpqbtqH9dSe v+1l9w1EtbuSQVW3brQRHWfHe4qdX3g= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-114-PyTNT1xkPVOlVfmjfu76eA-1; Fri, 17 Dec 2021 05:58:03 -0500 X-MC-Unique: PyTNT1xkPVOlVfmjfu76eA-1 Received: by mail-wm1-f72.google.com with SMTP id a203-20020a1c7fd4000000b0034574187420so1853112wmd.5 for ; Fri, 17 Dec 2021 02:58:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vfMj5Cdv9ABQA5uXGp3mACXyYa8FBWK9SwauD15vTUk=; b=rJo+I5k3gLCuk8F8vGJZzh0jWC5ovH85oIsdmdCtmHBkUR59TRub8qM+3k5WTwBvVz 9ts+uTHDaJ8jTxezYQRppj2Sy/WNP+vuYAhnc6TOHBZRV0w23cL05hi/lpP++UAvw1zi +716AJgopblqePOb7xkZ9QsdZhoHZWdiK0wg2UEQ27s6HLM1dE6NKipx6/mmlMlpDgv7 8isMGkEa2x40FmQo9Z38bjRnXUNdtg1QqRxSD6F/av658Y94sd+ubWfSZc9gLKntlRVo Kj58N8tAsWnI7zZIi5kJaHbpTibB5b00GAn/mAFSzGfU56dtrleJqJqBRsQKw1SSa2Fs eA/Q== X-Gm-Message-State: AOAM533+hbyWrrCBUq6OzAnOIu4nFi2R5/r7DEYAJqekqlsm+sceBAAB OM1ItV4XNo0B+nB7liZliFDLHCISFhKxOa1Ycw9ULNkpqeremTXWlATh294qoI3MC/zVc2UwUoQ OpKA5vyOvtHi5D0NARuDt8H1ZPKTBMGkNQNc= X-Received: by 2002:a05:600c:3ac6:: with SMTP id d6mr2240070wms.191.1639738682586; Fri, 17 Dec 2021 02:58:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJysepd7uhQTf9/QJszbG/jm5Yl980CRUzB5yGgrcxWsh+7XsGwRjPoBHPcTl4LGXQFGL0ZYgQ== X-Received: by 2002:a05:600c:3ac6:: with SMTP id d6mr2240054wms.191.1639738682352; Fri, 17 Dec 2021 02:58:02 -0800 (PST) Received: from vian.redhat.com ([2a0c:5a80:3b0e:bd00:1099:cf34:d27f:de8a]) by smtp.gmail.com with ESMTPSA id h5sm7405122wrz.63.2021.12.17.02.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Dec 2021 02:58:02 -0800 (PST) From: Nicolas Saenz Julienne To: tglx@linutronix.de, mark.rutland@arm.com, paulmck@kernel.org Cc: rostedt@goodmis.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rcu@vger.kernel.org, peterz@infradead.org, mtosatti@redhat.com, frederic@kernel.org, corbet@lwn.net, Nicolas Saenz Julienne Subject: [PATCH v3 2/2] Documentation: core-api: entry: Add comments about nesting Date: Fri, 17 Dec 2021 11:57:53 +0100 Message-Id: <20211217105753.892855-2-nsaenzju@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211217105753.892855-1-nsaenzju@redhat.com> References: <20211217105753.892855-1-nsaenzju@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=nsaenzju@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211217_025807_285153_C97EE784 X-CRM114-Status: GOOD ( 13.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The topic of nesting and reentrancy in the context of early entry code hasn't been addressed so far. So do it. Signed-off-by: Nicolas Saenz Julienne --- NOTE: I moved this into a separate patch to simplify the review. Documentation/core-api/entry.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/core-api/entry.rst b/Documentation/core-api/entry.rst index 3f80537f2826..f665f201ead0 100644 --- a/Documentation/core-api/entry.rst +++ b/Documentation/core-api/entry.rst @@ -105,6 +105,8 @@ has to do extra work between the various steps. In such cases it has to ensure that enter_from_user_mode() is called first on entry and exit_to_user_mode() is called last on exit. +Syscalls shouldn't nest. If it were to happen, RCU / context tracking will +catch the misbehavior and print out a warning. KVM --- @@ -121,6 +123,9 @@ Task work handling is done separately for guest at the boundary of the vcpu_run() loop via xfer_to_guest_mode_handle_work() which is a subset of the work handled on return to user space. +Nesting doesn't make sense in the context of KVM entry/exit transitions, it +shouldn't happen. + Interrupts and regular exceptions --------------------------------- @@ -180,6 +185,16 @@ before it handles soft interrupts, whose handlers must run in BH context rather than irq-disabled context. In addition, irqentry_exit() might schedule, which also requires that HARDIRQ_OFFSET has been removed from the preemption count. +Even though interrupt handlers are expected to run with local interrupts +disabled, interrupt nesting is common from an entry/exit perspective. For +example, softirq handling happens within an irqentry_{enter,exit}() block, with +local interrupts enabled. Also, although uncommon, nothing prevents an +interrupt handler from re-enabling interrupts. + +Interrupt entry/exit code doesn't strictly need to handle reentrancy, since it +runs with local interrupts disabled. But NMIs can happen anytime, and a lot of +the entry code is shared between the two. + NMI and NMI-like exceptions --------------------------- @@ -259,3 +274,7 @@ and for e.g. a debug exception it can look like this: There is no combined irqentry_nmi_if_kernel() function available as the above cannot be handled in an exception-agnostic way. + +NMIs can happen in any context. For example, an NMI-like exception triggered +while handling an NMI. So NMI entry code has to be reentrant and state updates +need to handle nesting.