From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DCCAC433EF for ; Mon, 29 Nov 2021 14:58:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADD766B0071; Mon, 29 Nov 2021 09:58:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A8C916B0072; Mon, 29 Nov 2021 09:58:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 906BF6B0073; Mon, 29 Nov 2021 09:58:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8231A6B0071 for ; Mon, 29 Nov 2021 09:58:46 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 492FF180A72EB for ; Mon, 29 Nov 2021 14:58:36 +0000 (UTC) X-FDA: 78862274148.17.97486DA Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf18.hostedemail.com (Postfix) with ESMTP id DB8AF400209B for ; Mon, 29 Nov 2021 14:58:30 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 589521FD38; Mon, 29 Nov 2021 14:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1638197914; h=from:from:reply-to: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=9t4Ma3afwC7KZw9L0yhc6vlBZ0A17MFGlznwnQnwnFg=; b=FgA1wOJzo4HWeOGYsqs1Zn9+9sqilkSru5Aiywz0Oon3jZv67bxJPpasmLSyZ2l1Vlv5s1 dKibSpK7WF9Cc9w3jIRANiQHhN7ATD7KcS/Npo2/pKhM2fMxVyfEC9fG0ALxvnG/1DvJqH +/JkHW8nIC7fvLwz+blvFMdSbsreDUo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1638197914; h=from:from:reply-to: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=9t4Ma3afwC7KZw9L0yhc6vlBZ0A17MFGlznwnQnwnFg=; b=TH1LAL3X3oY2ggbvSxH/DMeiro4vt3B0XxLrZZ/ByD6KFnMZGaRFU+xA8YGi19PJzN7t/B MZhaDO3lvRW1xaCw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CAAEA13B2B; Mon, 29 Nov 2021 14:58:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uevfMJnqpGH6EQAAMHmgww (envelope-from ); Mon, 29 Nov 2021 14:58:33 +0000 Message-ID: <7e368c50-ff94-d87e-e93f-bae044659152@suse.cz> Date: Mon, 29 Nov 2021 15:58:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Content-Language: en-US To: Brijesh Singh , Joerg Roedel , Dave Hansen Cc: Peter Gonda , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com References: <20210820155918.7518-1-brijesh.singh@amd.com> <5f3b3aab-9ec2-c489-eefd-9136874762ee@intel.com> <38282b0c-7eb5-6a91-df19-2f4cfa8549ce@intel.com> <9503ac53-1323-eade-2863-df11a5f36b6a@amd.com> From: Vlastimil Babka Subject: Re: [PATCH Part2 v5 00/45] Add AMD Secure Nested Paging (SEV-SNP) Hypervisor Support In-Reply-To: <9503ac53-1323-eade-2863-df11a5f36b6a@amd.com> Content-Type: text/plain; charset=UTF-8 X-Rspamd-Queue-Id: DB8AF400209B X-Stat-Signature: gnzejoy8iq88meh6f6gzfyykj86mrx4n Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=FgA1wOJz; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=TH1LAL3X; dmarc=none; spf=pass (imf18.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspamd-Server: rspam02 X-HE-Tag: 1638197910-171865 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 11/29/21 15:44, Brijesh Singh wrote: >=20 >=20 > On 11/25/21 4:05 AM, Joerg Roedel wrote: >> On Wed, Nov 24, 2021 at 09:48:14AM -0800, Dave Hansen wrote: >>> That covers things like copy_from_user().=C2=A0 It does not account f= or >>> things where kernel mappings are used, like where a >>> get_user_pages()/kmap() is in play. >> >> The kmap case is guarded by KVM code, which locks the page first so th= at >> the guest can't change the page state, then checks the page state, and >> if it is shared does the kmap and the access. >=20 >=20 > The KVM use-case is well covered in the series, but I believe Dave is > highlighting what if the access happens outside of the KVM driver (such= as a > ptrace() or others). AFAIU ptrace() is a scenario where the userspace mapping is being gup-ped= , not a kernel page being kmap()ed? > One possible approach to fix this is to enlighten the kmap/unmap(). > Basically, move the per page locking mechanism used by the KVM in the > arch-specific code and have kmap/kunmap() call the arch hooks. The arch > hooks will do this: >=20 > Before the map, check whether the page is added as a shared in the RMP > table. If not shared, then error. > Acquire a per-page map_lock. > Release the per-page map_lock on the kunmap(). >=20 > The current patch set provides helpers to change the page from private = to > shared. Enhance the helpers to check for the per-page map_lock, if the > map_lock is held then do not allow changing the page from shared to pri= vate. That could work for the kmap() context. What to do for the userspace context (host userspace)? - shared->private transition - page has to be unmapped from all userspace= , elevated refcount (gup() in progress) can block this unmap until it goes away - could be doable - still, what to do if host userspace then tries to access the unmapped page? SIGSEGV instead of SIGBUS and it can recover? > Thoughts ? >=20 >> >> This should turn an RMP fault in the kernel which is not covered in th= e >> uaccess exception table into a fatal error. >> >> Regards, >>