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 F1CBDC77B73 for ; Thu, 20 Apr 2023 16:31:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78503900004; Thu, 20 Apr 2023 12:31:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70E0A900002; Thu, 20 Apr 2023 12:31:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AF69900004; Thu, 20 Apr 2023 12:31:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4A656900002 for ; Thu, 20 Apr 2023 12:31:25 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 137FE40263 for ; Thu, 20 Apr 2023 16:31:25 +0000 (UTC) X-FDA: 80702309730.30.F873A1C Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf22.hostedemail.com (Postfix) with ESMTP id 4694CC0004 for ; Thu, 20 Apr 2023 16:31:21 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=S9pFjdEC; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=kRdOKfwl; spf=pass (imf22.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682008281; h=from:from:sender: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:dkim-signature; bh=2vbLoApHWWuDvlIYJY/7MrXOyrVieSuLGNdDWo7gZ4I=; b=P5/9REPstbPneYoHeoZVdp6h9uh51VTX/KXR6U/SRLAb6zzhUl8NjsZtsYhrK6uiEb8MK8 05MjV03Kg4Ie06BBwx6l8Uitz/aaHFx8BHL9veBtQvyd/gy7bUX5/brRqez75rLhCb+5q7 7OAL0b/GUdsSemw6gEEerKJpgn538Go= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=S9pFjdEC; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=kRdOKfwl; spf=pass (imf22.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682008281; a=rsa-sha256; cv=none; b=opu0ME68KRIiRQ3rMMljKJ/PXdHwix35QK0VhduBFtXPa5moJ6nRIURUvX/wi33U9DXRCz pOrV/dAsxljFHjCXQ+Q47g8MAZdiNFcYBiy7rlWR2T2uXuA6ZM4tSBAggzCdDaGC6mxE8G DEXLlWrXJ7FVceUCbwuBuOe/azKZ2Zg= 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-out1.suse.de (Postfix) with ESMTPS id 977FF21A14; Thu, 20 Apr 2023 16:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1682008279; 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=2vbLoApHWWuDvlIYJY/7MrXOyrVieSuLGNdDWo7gZ4I=; b=S9pFjdEC0JTo/RCJM5CnYDyb/QoYQOzQy/CvitLpsvwmcChEObw0XZLw617Gw56a7+j3iD QpNsvrBE2AH/XaMx3KKlx48T0A9CzZXR8wcDodYGqxs33GkoK5DQNzxuCt8PfiwgwxAy7d j67iCDamnbETaMdR6k2EO0O2uU18DWU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1682008279; 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=2vbLoApHWWuDvlIYJY/7MrXOyrVieSuLGNdDWo7gZ4I=; b=kRdOKfwlpUyj0B8yvJsIRfqkatWgwOj9y7NQ2vqZDh088EhuZrNAMvaTHSqbYsT2uJTAxv aSNaixUKPGBz0zCg== 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 1789313584; Thu, 20 Apr 2023 16:31:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id vCD/BNdoQWSpegAAMHmgww (envelope-from ); Thu, 20 Apr 2023 16:31:19 +0000 Message-ID: <9c8829f6-8049-2c83-49a4-285757cc9259@suse.cz> Date: Thu, 20 Apr 2023 18:31:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH RFC v8 12/56] x86/sev: Add RMP entry lookup helpers Content-Language: en-US To: Michael Roth Cc: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, dovmurik@linux.ibm.com, tobin@ibm.com, bp@alien8.de, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, dgilbert@redhat.com, jarkko@kernel.org, ashish.kalra@amd.com, nikunj.dadhania@amd.com, Brijesh Singh References: <20230220183847.59159-1-michael.roth@amd.com> <20230220183847.59159-13-michael.roth@amd.com> <20230329225958.4s3nwcqyjwzydwsf@amd.com> From: Vlastimil Babka In-Reply-To: <20230329225958.4s3nwcqyjwzydwsf@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: 545jbqx6tn7m6yjgjp4dswxfjwfbcrng X-Rspam-User: X-Rspamd-Queue-Id: 4694CC0004 X-Rspamd-Server: rspam06 X-HE-Tag: 1682008281-649570 X-HE-Meta: U2FsdGVkX188LTb4GlMai5ZP3fQ3BmmxX0OEfkstrSMmML0ZoDe71WxFAQ2FtfY+b7pUQmrvZV4Ub22Y3QhSkoG7yIok2YPyr4hK+I7qqkr//kqepjhLcZCJJD6pJ1sXT/vW/uD8JG25Q1K2QBSxuspsV8hC0fUKht0Jv0RcwQzcZ07g2UTyuX0RKa7oDMDjP2HWwEn3Oj0sfOvXjvfcOm45ajkFfCxrtSNljuIpWK6NszzwtkrsVX6uyCXwH4HJrXDTRL80h0+ukp6V15Zt39Nd5kbSE+jAgktj9kIT/e4H2eVSvhWv7lrXYOmSDd01MF5NS1g73zIzfN5IMRnbirrPe/rIObpHjtHmAPnVn+C0c4V8bETNCAtIdM/aPfxHChmjJHKP3We6+0+ScOX43Io+yIsvEnBqzvteO7vEd3rlzyzOpKacylI78qoMpG4Cp59dUsc+153hrqAfOpoKBo63h8VfeUm2Sr+bxR02sKSv0bYmnrT2yh1p1WeotOssFghCheKRdPgsAXEmn/nL5M3k4oBz2wwSOX+wzr7BKjjmDYUolGvA9klgq1DJ9/w4VixQ7PPTAIQdn6osDWLHyMyu3jvJVxu3XYoQ3oxGHMySzH4BEBeQamujrhLJAVt1SUlSAeF1THjZI1RdRcOyobhPgtgVgL4S1CHsn8ZtM1QtrYEYWEKVFqLmM7PUA7VmjkKoDOURN7yAuMau820kMHCJgc1nkt48z0sSTN9SOOun9R5UmGwcIs+v57D6uxn7UUH4ooikFKUBI66Cjl4fU5yecZoNM22AhzsxGs9I5y1VNqTt/6PwOmZa1EVW9+fNzDClZjszIn6G6W+PYiTbAKNue+5ScmTBKzsy3iEO4P/X7DvG+oq1e0im6vA6DH5cmKfPd3YLBeweQ8LpdtFJupWf/Smif06+xIzISchRC8mB3MbCD5WqryiRRovIlpZfkPZzL3hSbAz2qr96ofZ lFQLWZhW Mnxrd5ISMLpsGksWzZnGscGG1cjq907SbbFaYWRapp0ANGFRnlwK8W+E3bV7d0daTOdszbrn6wt7ib6x+qbO0GkpiQqriTDmrrxSE7nxtFym/GLRxMescwF8OUuel78xX8j8XbkRnCL+e7JeK9LpfmVcNaOzE1jmXoSfjWJeeQCsBrPPrcCNbcJyj1Ow91nUs61SB5qWFSWelaVLsdLctCVQfjJDILyCa6i750jTq9+xEyMteqNl/nxCGlnjm9ToMQUKvop5X+il5YycGq1UbtZfaBy2wiLfTQsWIxHHGOIWq+lQ= 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 3/30/23 00:59, Michael Roth wrote: > On Fri, Mar 03, 2023 at 04:28:39PM +0100, Vlastimil Babka wrote: >> On 2/20/23 19:38, Michael Roth wrote: >> > From: Brijesh Singh >> > >> > The snp_lookup_page_in_rmptable() can be used by the host to read the RMP >> > entry for a given page. The RMP entry format is documented in AMD PPR, see >> > https://bugzilla.kernel.org/attachment.cgi?id=296015. >> > >> > Co-developed-by: Ashish Kalra >> > Signed-off-by: Ashish Kalra >> > Signed-off-by: Brijesh Singh >> > Signed-off-by: Michael Roth >> > --- >> >> > +/* >> > + * Return 1 if the RMP entry is assigned, 0 if it exists but is not assigned, >> > + * and -errno if there is no corresponding RMP entry. >> > + */ >> >> Hmm IMHO the kernel's idiomatic way is to return 0 on "success" and I'd >> assume the more intuitive expectation of success here if the entry is >> assigned? > > In general I'd agree. Here's it's a little awkward though. > snp_lookup_rmpentry() sort of wants to be a bool, where true indicates > an assigned entry was found, false indicates no assigned entry. > > But it also has to deal with error values, so the most direct way to > encapsulate that is true == 1, false == 0, and < 0 for errors. > > Inverting it to align more with kernel expections of 0 == success/true > gets awkward too, because stuff like: > > if (snp_lookup_rmpentry(...)) > //error > > still doesn't work the way most other functions written in this way > would since it could still be "successful" if we were expecting PFN to > be in shared state. So the return value needs special handling there > too. > > Would it make sense to define it something like this?: > > /* > * Query information about the RMP entry corresponding to the given > * PFN. > * > * Returns 0 on success, and -errno if there was a problem accessing > * the RMP entry. > */ > int snp_lookup_rmpentry(u64 pfn, int *level, bool *assigned) Yeah that looks fine to me. Hope you find out it makes it easier to work with in the callers too. > >> The various callers seem to differ though so I guess it depends on >> context. Some however don't distinguish their "failure" from an ERR and >> maybe they should, at least for the purposes of the various printks? > > Yes, regardless of what we decide above, the call-sites should properly > distinguish between failure/assigned/not-assigned and report the > information accordingly. I'll get those fixed up where needed. Great, thanks! > Thanks, > > -Mike > >> >> > +int snp_lookup_rmpentry(u64 pfn, int *level) >> > +{ >> > + struct rmpentry *e; >> > + >> > + e = __snp_lookup_rmpentry(pfn, level); >> > + if (IS_ERR(e)) >> > + return PTR_ERR(e); >> > + >> > + return !!rmpentry_assigned(e); >> > +} >> > +EXPORT_SYMBOL_GPL(snp_lookup_rmpentry); >>