Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2374046rwb; Thu, 17 Nov 2022 09:54:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Ls8p8s5dyNFHKKQ97hb12ydP/4OBveoIWu/98wzQL5KyhYeoM9wo9JyYEGKK5P5p8Mu2r X-Received: by 2002:a17:906:88d:b0:783:978:b39d with SMTP id n13-20020a170906088d00b007830978b39dmr3094178eje.349.1668707642801; Thu, 17 Nov 2022 09:54:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668707642; cv=none; d=google.com; s=arc-20160816; b=WLcgmcjJcU3c3Ga7xVmnFF3JMNQE0odAuirGQL00aR5wthls7PgmlK0G4/U7xTIvuS 7xglx+R4n46+sbVfr7TrHj4gRskmmxPj11E0P+omYlOe0jEgY/TMTET6QBuKyBruwAJ3 +TUMHTk+204RCJLBr0HkyqmtH9Mz4ft1c3chLH+9NIlBVGk7C5MbxUdRpoSZOmEZSRxi L6v8k05qrJ/LzQ/4P6pQWgvmu+05WjjaDFvSbZagG9rwFHpmTrEKfkoXmcQiGDAThgFw lUvoxuritnRkLbHsSZOPCc3PD98z8QycWS03Uf+8aD+mtKPo8DSsM+GVrXq84Lkm1PDi cFGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=GpTmGyle5XHjW7gvyvHxuCwQpZoXDUrLr0aG4rFAVf8=; b=WIYJqRZmOC3M/iQZpS0Eoma957Vy4aAN2eLMVHKSOQg4FROUTwbE0oyOlUURowfXxH yFkmHbGCxZ/C4z5LhMn+9dVitKANtoy05uk/gI0syTQyjOtqWDbhgGZkYRIV4CLFmxz/ KMGyd1nJ+BIfdU6HTdPc7Md52RkcjCLlXZ7G7aUA/niLDWUNbJtRXxYceVv9HvF0xmXa 1lbBSFweP99+t/LZqgQ8dsKqFoK2yRFOY0bVUMY8nMuKLPPks0TmymFQFWpGm7tYxyZY mQ30JyXoGCYNdoxCXSVL8rUUZUB9So+L4yAUwH4UU526hGhQHNKdGP/Cm+rK0gXy48Q8 5IcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Z2kCiadh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z3-20020a1709067e4300b00711da52c6e4si899830ejr.309.2022.11.17.09.53.40; Thu, 17 Nov 2022 09:54:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Z2kCiadh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239817AbiKQRe7 (ORCPT + 92 others); Thu, 17 Nov 2022 12:34:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbiKQRe6 (ORCPT ); Thu, 17 Nov 2022 12:34:58 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AA04532EB; Thu, 17 Nov 2022 09:34:57 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id k22so2452450pfd.3; Thu, 17 Nov 2022 09:34:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=GpTmGyle5XHjW7gvyvHxuCwQpZoXDUrLr0aG4rFAVf8=; b=Z2kCiadhuB3UXfJf81kDm8ji1v9Db3bAW+nVpWQopH+ASUM3NfA2hLMB/YGHkEZdkj +g+o3hYtU9dUSCMVdnRK+oHtUwfCPt6kFPzXPDvsIUCw8qHXHnHXhnBN/VkZ69BukmPT nb7+YZGkny0COiexyK2R25oFBkSkp3kvGVibjiDBEuDU9bUwhfhkjp5jLglRb3ehdrw1 /Vs3oTvkjusQ6BxYV3Ylybh5tNCzw3hXVmV4qZrcCPOzAi0+3mp9GCWhD6lACAXJ4WH0 zTK0YJiTYXWOp2I/zdR/00DEEm4lzl2HM7vIyqNvRKKCtySsgVjIMRbrITvnqsXkrlBe vnoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=GpTmGyle5XHjW7gvyvHxuCwQpZoXDUrLr0aG4rFAVf8=; b=0XgZwGUi0aAuBp9/+BLeKPnmx4roEcB+xFEUrPp2tDT8pCM6JouMOA4+yD2M0YGzgl 9cwPFiJISPx7QtYKJ15NhGQaJSnVzl4oApLf/36Lqj4pxWMtc0GBAL5OejdIzKloO783 fraxBpaIT6XiPKXavwxvGFBuZPiWUqJct+g07gSScS4CfL+qYRSeUOY8UFC4rsj1I8iE bQOXYfHvSVorgQ4+XpNf5KJr2a0ZyLuDW4RpR0YQ9g9YO9Q148j09LdZkjTko1fmfCvS Qpl6JrN5vR/AQA34boY3ypj9s1ZKEdblfvND4coS8sL0iFGzQ3bsjxy8DBY6pfJgvjdX dLHw== X-Gm-Message-State: ANoB5pmIYZST8ORoYw8zJJz/aGGvRXyx6DHbKuKCF0OdYp0wB0/8TKi1 cIp1zJ9ATddu01SL1TpXaeg= X-Received: by 2002:a65:6a55:0:b0:470:2c92:13da with SMTP id o21-20020a656a55000000b004702c9213damr3005461pgu.298.1668706496897; Thu, 17 Nov 2022 09:34:56 -0800 (PST) Received: from localhost ([192.55.54.55]) by smtp.gmail.com with ESMTPSA id t15-20020a170902b20f00b00188ef2314b0sm1667673plr.39.2022.11.17.09.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 09:34:56 -0800 (PST) Date: Thu, 17 Nov 2022 09:34:55 -0800 From: Isaku Yamahata To: "Huang, Kai" Cc: "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Yamahata, Isaku" , "pbonzini@redhat.com" , "Shahar, Sagi" , "Aktas, Erdem" , "isaku.yamahata@gmail.com" , "dmatlack@google.com" , "Christopherson,, Sean" Subject: Re: [PATCH v10 015/108] x86/cpu: Add helper functions to allocate/free TDX private host key id Message-ID: <20221117173455.GC2350331@ls.amr.corp.intel.com> References: <5ee7c6dc4ba03b5d5166e015c148ef534ee53f8e.1667110240.git.isaku.yamahata@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 08, 2022 at 09:16:57AM +0000, "Huang, Kai" wrote: > On Sat, 2022-10-29 at 23:22 -0700, isaku.yamahata@intel.com wrote: > > From: Isaku Yamahata > > > > TDX private host key id is assigned to guest TD. The memory controller > > encrypts guest TD memory with the assigned TDX private host key id (HIKD). > ^ > HKID. > > And since you already mentioned in the first sentence, you can put (HKID) part > there. And I think you can just use HKID in the rest places to save some typing > as this is the purpose of using (HKID) I suppose. > > [...] > > > > > +/* TDX KeyID pool */ > > +static DEFINE_IDA(tdx_keyid_pool); > > + > > +int tdx_keyid_alloc(void) > > +{ > > + if (WARN_ON_ONCE(!tdx_keyid_start || !tdx_keyid_num)) > > + return -EINVAL; > > + > > + /* The first keyID is reserved for the global key. */ > > + return ida_alloc_range(&tdx_keyid_pool, tdx_keyid_start + 1, > > + tdx_keyid_start + tdx_keyid_num - 1, > > + GFP_KERNEL); > > +} > > +EXPORT_SYMBOL_GPL(tdx_keyid_alloc); > > + > > +void tdx_keyid_free(int keyid) > > +{ > > + /* keyid = 0 is reserved. */ > > + if (!keyid || keyid <= 0) > > + return; > > Double check of keyid == 0. > > I think you can just use: > > if (keyid <= tdx_keyid_start) > return; > > And/or add a WARN() as it's a bug if above happens. Ok. Will fix it with WARN(). -- Isaku Yamahata