From patchwork Mon Jan 10 10:50:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 12708581 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 24059C433EF for ; Mon, 10 Jan 2022 10:52: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=I7aU7ThCt7KKMbtTjU57N+q90GqL2DfgpDEzfaZP85c=; b=syMs1Xwig3Eq6/ gkILHwS97MhchgwV+m2C5C62o+9oJdgcAZ2SjjiOdWjdPUVqHZ7NQyVUQWgeYqQ5l8T8xJW4td0jf SMSv8mqJc3CVeL5wgp0JKrCaTx+WPbEBB1gW0pNZIWryVdCCDpygPwHC5Qu7yTrU4OSQzRMpRsvAl bSiEWS1gD3jTV2pIzpLJZqNd9c8CcvQgLTrTxd75bWtu1xY4VIAzwE3/JS7SUU/Kms6CVVhUpdA6H MNP0yURv2vHwNYXDAbPKXAh/iSVntk1wxm6T0NzIdjpmowEu3OMCK7WTxUtWnfOsL8nNqgxe7ZybA RNhDw0W/jdx5yVZPNT2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n6sGP-00Avo7-UM; Mon, 10 Jan 2022 10:50:58 +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 1n6sGK-00Avkv-6f for linux-arm-kernel@lists.infradead.org; Mon, 10 Jan 2022 10:50:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641811850; 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=SbyEAGXm6uVAR10E6kW8QyvfQbDxdraL/FSOR9ycncM=; b=YY1ldV4VMJEOo5ZePicodZHI3DapNpyH6X17X2BhgWJCXq+thbrQl/cfBT/LIbfzGmvt4F /XC8bRXFsMOKDufkwWjha7xZED1q/PCA3nK/EhU2kybz2HRZyCTNXC7jw2PuD59uxlD4bd gsk+JsBnEWctJQQEmDUrsDNX6VBlfMM= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-632-Fn5LSLUEPPqUX6oKiLRgiQ-1; Mon, 10 Jan 2022 05:50:49 -0500 X-MC-Unique: Fn5LSLUEPPqUX6oKiLRgiQ-1 Received: by mail-wr1-f69.google.com with SMTP id d14-20020adfa34e000000b001a631cb3ab5so2298816wrb.12 for ; Mon, 10 Jan 2022 02:50:48 -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=SbyEAGXm6uVAR10E6kW8QyvfQbDxdraL/FSOR9ycncM=; b=b9bAQ7WSnGZOhI/nq98chCnP5EQcaVdVQbDz4Prhi7zUAfY2WHEsD+3GK0cp8pzwNl 06jKS4FCu70+df0Uv5zcgXS5sTVltwVQzvGTddMw/4OGWDfrKiuFEVC4XlG1jZ7SE/3P i7Q51rMtxAidj9KMMclfwxnrV/IWLICyBs4LCMyCZAcIigujuo+5ueKkuTRPx9moC/I/ puERtj7Ja3zKdFuHTaLMvbffN/tyH/dlhatDVq8ELe/yLYdsD0oMCv+1tSJFyOrnFqAp sUJj1jX/FEJo/Ttb1sg6won0uBkknL6yudIxT4AhS1jNTyGLBqD0lLm57BH347/SwGhk zkxQ== X-Gm-Message-State: AOAM5304Iva9mmsVDtwXBYeiRJY88Hl/yKrcqbJugEzKSoHcJismp62a MqWvXLyHkk0a3BKql3ZM0zRnm8d/tZzywNKHKAduW8BX+WuM8ehktsug39fTG2MeLSUMPp8Oeks pbjCgVHYmmggkEhzt7OtqMpWF0Klkr5QsvIk= X-Received: by 2002:a7b:c305:: with SMTP id k5mr21416711wmj.144.1641811847842; Mon, 10 Jan 2022 02:50:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJysN9EkPLfD6O/v+iNsqBZ2ymYyZycxdVBE8rH21g120evtaf2rhvzsHLMdH6me9L3zGbBSpA== X-Received: by 2002:a7b:c305:: with SMTP id k5mr21416701wmj.144.1641811847602; Mon, 10 Jan 2022 02:50:47 -0800 (PST) Received: from vian.redhat.com ([2a0c:5a80:1e09:d600:637e:7f1b:a4a0:fc92]) by smtp.gmail.com with ESMTPSA id r1sm7051224wrz.30.2022.01.10.02.50.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jan 2022 02:50:47 -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 v4 2/2] Documentation: core-api: entry: Add comments about nesting Date: Mon, 10 Jan 2022 11:50:44 +0100 Message-Id: <20220110105044.94423-2-nsaenzju@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220110105044.94423-1-nsaenzju@redhat.com> References: <20220110105044.94423-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-20220110_025052_472394_599AA759 X-CRM114-Status: GOOD ( 14.47 ) 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 Reviewed-by: Paul E. McKenney Reviewed-by: Frederic Weisbecker --- Changes since v3: - Introduce Paul's rewording suggestions Documentation/core-api/entry.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Documentation/core-api/entry.rst b/Documentation/core-api/entry.rst index c6f8e22c88fe..e12f22ab33c7 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. +Do not nest syscalls. Nested systcalls will cause RCU and/or context tracking +to print a warning. KVM --- @@ -121,6 +123,8 @@ 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. +Do not nest KVM entry/exit transitions because doing so is nonsensical. + Interrupts and regular exceptions --------------------------------- @@ -180,6 +184,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 +273,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.