[v4,1/4] KVM: SVM: Set sev->asid in sev_asid_new() instead of overloading the return
Message ID | 20240131235609.4161407-2-seanjc@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-47400-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp113689dyc; Wed, 31 Jan 2024 16:24:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IH52msyqw7JHx4ON3Et19XQWwFnNIti9fNtddQR8COR2Mp2kl6cKraWulcHdTHsAlZ4YY9K X-Received: by 2002:a17:902:d4d2:b0:1d9:8f7:dd26 with SMTP id o18-20020a170902d4d200b001d908f7dd26mr3376078plg.5.1706747085680; Wed, 31 Jan 2024 16:24:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706747085; cv=pass; d=google.com; s=arc-20160816; b=sAwFXP8S9s/JCyWXA4x9Miobd3b/14jEnCIwU/VE42oLZje/CJY8BCx3+Vr4/J0BOR r1H2AEZFirEcpriII0DFeMECmlVDqMyTXVJMdd5coaVOzHZ/h0WOcjC0+K2uo1PS1ZF9 nrz14DeJ5UZSitK9XsgDKWDJYh66tHeLns3zDn9KDwGZE1HWfkuEnXOP3WdcbgSl1N0y 3TXsDkgQApiL2QHr9yREYzbZYaJEWI9GjOQkGE4oZ76o7fLPdOcAEzfx9DFqQOWYPMB3 tgBUXhbNJ9gL5TtOUQcb7sYdLfOUTgKzzvHdc33cou4yIAdBC3BIvxY2J9zt5WdfgGbk jwqA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=CQD8xVAMwqMOWi6PTJB0HJDtmdm31D4WNpxMiUSqPiQ=; fh=IWYwZbAId54j9xn8fsQDFqHpDP7OaSnDy1SjQjifh/w=; b=OYutcT6C/5TBihjKCMxzDGC/szczjLMlYxbjmxhex8VOS8lQMjyqQfST1/zyHWYNFi Q9DcOY0BmK6sGSQWQC0wOnXjvWEqYaG5MtQYnJpubzLGuueGiRJAO2r4BK1jLc6YZxMZ j0CU5/Wife9l+wLOu+qVY2ferjCEaVCELJGAqhAqCQmY+l3EkWL/rNNiXpZ/4PdZmz/Y CO03bSU9lorqGzjippQYvDn7PVaP+0ZDd0KpaxriatTvBdLw0FoZhyj7ITJFR0K4x+l7 YbrrtGiOl7OMeXKhB+pAyCyLS3BXMoJjX/TaKas8RHitAhHGKygWuhw4kGjoKqmY0ZLI KcNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QdSWPBrH; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47400-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47400-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCXxs8mG2fRqlzuLMuJQ2/n0BavvmhgsNvPqf9LSns1Kea5DgFeUQMt1yhv3fe0n4FUNR1GKYS9m2lM7Xtq/1Pgmg7gDnQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d19-20020a170902729300b001d93c10adefsi1515315pll.631.2024.01.31.16.24.45 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 16:24:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47400-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QdSWPBrH; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47400-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47400-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4B546B2D746 for <ouuuleilei@gmail.com>; Wed, 31 Jan 2024 23:57:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 21BBD3CF6B; Wed, 31 Jan 2024 23:56:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QdSWPBrH" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 832F73B19B for <linux-kernel@vger.kernel.org>; Wed, 31 Jan 2024 23:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706745376; cv=none; b=bmPwlf2Z+HPBdlREXK4r48UkAMU3RCJnlsU3rpkXiyFQxek+hG6mO5VTuSPufhqX7ZcG02BEpLSmAoAW9WFZzg0OLLVE7hLrcdtQ3OdNYpLH3kFH5uh1Ef6K7OYI22CLoESiviI7TsjCLWv1+60enkGCFfxjZI8A8HeGwQunZ4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706745376; c=relaxed/simple; bh=C2Mp5wDF+w5HYei1nLihykDqJ+peIrgUvLAyytBwPBU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=shkvWmUSeqtHwMaAEJjkeyd8+7h0HENR8YdQIbEuf26g/MkLBYViD697QP//3ym4hWa46VhN9DbQxwZ/8FzHe7/gsALBs8/McWltMD/pvXXsyfLKp5az+vZsbVZyF9nwD62GBypvyDrS7wcwYrDmg00O67uBl5qofud4zRexzMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QdSWPBrH; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60406626b50so7863977b3.0 for <linux-kernel@vger.kernel.org>; Wed, 31 Jan 2024 15:56:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706745373; x=1707350173; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=CQD8xVAMwqMOWi6PTJB0HJDtmdm31D4WNpxMiUSqPiQ=; b=QdSWPBrHomk20lzUGbh0sGV4DlQIZgWvcIOlSeU+SvoGq4ZqXlm3BAeLhfaA8+1lv8 mMJ2JM9bYLHtBdN4+utWr47sJlauQ8DZjxoadFqKfIv/SGjfd53gidHQU1itQuBygbYq 21AC1wKE/mv0pxC4S1u8z521kI9bg8UJFljJdyzhCr6OJ6Si2ZSAtklEO28JduH8XJOc 6F+bljjU5K7OqwB+N+IFWxZAFqI9+FpEHv/9YJiEFDjw73kU07ADdG5AR77DAU2//z5l tdPPHsaa/KdYvbLrzWufCdkIdk8Q8ODIUU9HBsFWn6NYu341dvpFT7LTTvOS76FUzErK epzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706745373; x=1707350173; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CQD8xVAMwqMOWi6PTJB0HJDtmdm31D4WNpxMiUSqPiQ=; b=ND1ZEw5w6HnTojVUCOX7YQTK/lYhF/L6lP4swI3EXtgjM79UC12EQJ31N65RWMTYcY jFvCSxvWpI6dW8CpC6+Z+xfa3Fvyp59cYeJhTvfRdxeVEm9fvyFot/kE07ttiM6dZ7+W g70zPLR1eyT6U/x4qV/+n/MRBYuXcTtqO+z/vEaeld1eJJS9znrZf6BzXMp+I/OvUtUx sCUMWq0Ddy1bLpQS/ndDNbDM6RpVEMik3JC9/TQ93cPXERVF1NQ6vD8MGAanFh+4/826 /oxuhGIXCU7NWY7H3C2b96vM+bLFjUCqbFW3rWgieZ8m+WRjE9etvf7aBhRFKK3HnIkL X7oA== X-Gm-Message-State: AOJu0Yxg7Ix/DN29O6Ulgg3kFiWpcHCQ94lsfUSqoErhk0WTNX3V0VuD F5vyrCTMYPif4rT/G6s6mWevKjvsso9625rv92BSoD0pU+RxkR/bI1Tq+dQiWBlZ97lttyPnArd opQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1385:b0:dc2:3441:897f with SMTP id x5-20020a056902138500b00dc23441897fmr859913ybu.6.1706745373557; Wed, 31 Jan 2024 15:56:13 -0800 (PST) Reply-To: Sean Christopherson <seanjc@google.com> Date: Wed, 31 Jan 2024 15:56:06 -0800 In-Reply-To: <20240131235609.4161407-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> Mime-Version: 1.0 References: <20240131235609.4161407-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240131235609.4161407-2-seanjc@google.com> Subject: [PATCH v4 1/4] KVM: SVM: Set sev->asid in sev_asid_new() instead of overloading the return From: Sean Christopherson <seanjc@google.com> To: Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com> Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ashish Kalra <ashish.kalra@amd.com>, Tom Lendacky <thomas.lendacky@amd.com> Content-Type: text/plain; charset="UTF-8" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789654031962769899 X-GMAIL-MSGID: 1789654031962769899 |
Series |
Add support for allowing zero SEV ASIDs
|
|
Commit Message
Sean Christopherson
Jan. 31, 2024, 11:56 p.m. UTC
Explicitly set sev->asid in sev_asid_new() when a new ASID is successfully
allocated, and return '0' to indicate success instead of overloading the
return value to multiplex the ASID with error codes. There is exactly one
caller of sev_asid_new(), and sev_asid_free() already consumes sev->asid,
i.e. returning the ASID isn't necessary for flexibility, nor does it
provide symmetry between related APIs.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/svm/sev.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
Comments
On 1/31/24 17:56, Sean Christopherson wrote: > Explicitly set sev->asid in sev_asid_new() when a new ASID is successfully > allocated, and return '0' to indicate success instead of overloading the > return value to multiplex the ASID with error codes. There is exactly one > caller of sev_asid_new(), and sev_asid_free() already consumes sev->asid, > i.e. returning the ASID isn't necessary for flexibility, nor does it > provide symmetry between related APIs. > > Signed-off-by: Sean Christopherson <seanjc@google.com> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> > --- > arch/x86/kvm/svm/sev.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > index f760106c31f8..7c000088bca6 100644 > --- a/arch/x86/kvm/svm/sev.c > +++ b/arch/x86/kvm/svm/sev.c > @@ -179,7 +179,8 @@ static int sev_asid_new(struct kvm_sev_info *sev) > > mutex_unlock(&sev_bitmap_lock); > > - return asid; > + sev->asid = asid; > + return 0; > e_uncharge: > sev_misc_cg_uncharge(sev); > put_misc_cg(sev->misc_cg); > @@ -246,7 +247,7 @@ static void sev_unbind_asid(struct kvm *kvm, unsigned int handle) > static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) > { > struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; > - int asid, ret; > + int ret; > > if (kvm->created_vcpus) > return -EINVAL; > @@ -257,10 +258,9 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) > > sev->active = true; > sev->es_active = argp->id == KVM_SEV_ES_INIT; > - asid = sev_asid_new(sev); > - if (asid < 0) > + ret = sev_asid_new(sev); > + if (ret) > goto e_no_asid; > - sev->asid = asid; > > ret = sev_platform_init(&argp->error); > if (ret)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index f760106c31f8..7c000088bca6 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -179,7 +179,8 @@ static int sev_asid_new(struct kvm_sev_info *sev) mutex_unlock(&sev_bitmap_lock); - return asid; + sev->asid = asid; + return 0; e_uncharge: sev_misc_cg_uncharge(sev); put_misc_cg(sev->misc_cg); @@ -246,7 +247,7 @@ static void sev_unbind_asid(struct kvm *kvm, unsigned int handle) static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) { struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; - int asid, ret; + int ret; if (kvm->created_vcpus) return -EINVAL; @@ -257,10 +258,9 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) sev->active = true; sev->es_active = argp->id == KVM_SEV_ES_INIT; - asid = sev_asid_new(sev); - if (asid < 0) + ret = sev_asid_new(sev); + if (ret) goto e_no_asid; - sev->asid = asid; ret = sev_platform_init(&argp->error); if (ret)