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 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 EC241C2BD09 for ; Mon, 24 Jun 2024 19:35:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:In-Reply-To:References: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=PjQxqd6mI43HLHT0ovqXQMbmHuGqAl+zkO2SsToQlcA=; b=npNTno1XPot1Jr7NAzqxacodBa fuqPfqlGSJNfp9fUhN4e56UJx1yhuEDiprTPP4w4lpqOL5fK2Za0h41Kj3NUBbij0meuyX9+CbbES IE7VbWwKgDH1vWO379AYIEV2dkbsYOqRAPHOcqO8jod+6kaXPeXtmAgJFnS0F8ABK5VzfyfSYnds7 soXv3dJolmgWYcZxhFqqWnYLu1tjInG4W/IMJSbNQ8yGNiGSrFHNVJcEG2dyXgI4hLNHrcwhHtTtM LfHjFenqneE/8lNXGETYOjGX6yOGkpdbpMNQinEPJghLpZrxqTNu7vlPPMzJkos6frP8fgwQcVjOM YeeJunJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLpSq-00000000RlH-2COk; Mon, 24 Jun 2024 19:34:56 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLpSj-00000000RiC-1mAm for linux-arm-kernel@lists.infradead.org; Mon, 24 Jun 2024 19:34:51 +0000 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4W7J5p6Cd9z6K9gr; Tue, 25 Jun 2024 03:33:02 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id B89FF140519; Tue, 25 Jun 2024 03:34:42 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (7.191.163.240) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 24 Jun 2024 20:34:42 +0100 Received: from lhrpeml500005.china.huawei.com ([7.191.163.240]) by lhrpeml500005.china.huawei.com ([7.191.163.240]) with mapi id 15.01.2507.039; Mon, 24 Jun 2024 20:34:42 +0100 From: Shameerali Kolothum Thodi To: Oliver Upton CC: "kvmarm@lists.linux.dev" , "iommu@lists.linux.dev" , "linux-arm-kernel@lists.infradead.org" , Linuxarm , "kevin.tian@intel.com" , "jgg@ziepe.ca" , "alex.williamson@redhat.com" , "maz@kernel.org" , "will@kernel.org" , "robin.murphy@arm.com" , "jean-philippe@linaro.org" , Jonathan Cameron Subject: RE: [RFC PATCH v2 2/7] KVM: arm64: Introduce support to pin VMIDs Thread-Topic: [RFC PATCH v2 2/7] KVM: arm64: Introduce support to pin VMIDs Thread-Index: AQHaWqKYmx5fQRdWqUK/xtfkrTETwbHYEaEAgAARp0A= Date: Mon, 24 Jun 2024 19:34:42 +0000 Message-ID: <99b822b154504531b490055bc0f4006c@huawei.com> References: <20240208151837.35068-1-shameerali.kolothum.thodi@huawei.com> <20240208151837.35068-3-shameerali.kolothum.thodi@huawei.com> In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.195.246.162] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240624_123449_827318_714556F3 X-CRM114-Status: GOOD ( 19.20 ) 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 > -----Original Message----- > From: Oliver Upton > Sent: Monday, June 24, 2024 8:22 PM > To: Shameerali Kolothum Thodi > Cc: kvmarm@lists.linux.dev; iommu@lists.linux.dev; linux-arm- > kernel@lists.infradead.org; Linuxarm ; > kevin.tian@intel.com; jgg@ziepe.ca; alex.williamson@redhat.com; > maz@kernel.org; will@kernel.org; robin.murphy@arm.com; jean- > philippe@linaro.org; Jonathan Cameron > Subject: Re: [RFC PATCH v2 2/7] KVM: arm64: Introduce support to pin > VMIDs >=20 > Hi Shameer, >=20 > On Thu, Feb 08, 2024 at 03:18:32PM +0000, Shameer Kolothum wrote: >=20 > [...] >=20 > > +unsigned long kvm_arm_pinned_vmid_get(struct kvm_vmid *kvm_vmid) > > +{ > > + unsigned long flags; > > + u64 vmid; > > + > > + if (!pinned_vmid_map) > > + return 0; >=20 > Like I'd mentioned over in the other thread, returning 0 for error > conditions is rather confusing unless one is staring at the VMID > allocator code. Agree. It gives the impression VMID 0 is valid. >=20 > Can you rework this to return an actual error (e.g. -EINVAL) on failure? Ok. >=20 > > + raw_spin_lock_irqsave(&cpu_vmid_lock, flags); > > + > > + vmid =3D atomic64_read(&kvm_vmid->id); > > + > > + if (refcount_inc_not_zero(&kvm_vmid->pinned)) > > + goto out_unlock; > > + > > + if (nr_pinned_vmids >=3D max_pinned_vmids) { > > + vmid =3D 0; > > + goto out_unlock; > > + } >=20 > You need to decrement the refcount in this error path. Hmm..do we? We are here means refcount is zero, right? >=20 > > + > > + /* > > + * If we went through one or more rollover since that VMID was > > + * used, make sure it is still valid, or generate a new one. > > + */ > > + if (!vmid_gen_match(vmid)) > > + vmid =3D new_vmid(kvm_vmid); > > + > > + nr_pinned_vmids++; > > + __set_bit(vmid2idx(vmid), pinned_vmid_map); > > + refcount_set(&kvm_vmid->pinned, 1); > > + > > +out_unlock: > > + raw_spin_unlock_irqrestore(&cpu_vmid_lock, flags); > > + > > + vmid &=3D ~VMID_MASK; > > + > > + return vmid; > > +} > > + > > +void kvm_arm_pinned_vmid_put(struct kvm_vmid *kvm_vmid) > > +{ > > + unsigned long flags; > > + u64 vmid =3D atomic64_read(&kvm_vmid->id); > > + > > + if (!pinned_vmid_map) > > + return; > > + > > + raw_spin_lock_irqsave(&cpu_vmid_lock, flags); > > + > > + if (refcount_dec_and_test(&kvm_vmid->pinned)) { > > + __clear_bit(vmid2idx(vmid), pinned_vmid_map); > > + nr_pinned_vmids--; > > + } > > + > > + raw_spin_unlock_irqrestore(&cpu_vmid_lock, flags); > > +} > > + > > /* > > * Initialize the VMID allocator > > */ > > @@ -191,10 +263,20 @@ int __init kvm_arm_vmid_alloc_init(void) > > if (!vmid_map) > > return -ENOMEM; > > > > + pinned_vmid_map =3D bitmap_zalloc(NUM_USER_VMIDS, > GFP_KERNEL); > > + nr_pinned_vmids =3D 0; > > + > > + /* > > + * Ensure we have at least one emty slot available after rollover >=20 > typo: empty Thanks, Shameer