Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3414441rwb; Sat, 3 Dec 2022 04:44:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf6RXET3NISPZmh2DOmMkHH3RBbAqXoLd68urdycaguhkfcp2DjpXB4sOkrlGyhFJGraCAGh X-Received: by 2002:a63:f652:0:b0:478:5d66:90a with SMTP id u18-20020a63f652000000b004785d66090amr14317260pgj.546.1670071446146; Sat, 03 Dec 2022 04:44:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670071446; cv=none; d=google.com; s=arc-20160816; b=gXRPAFtwfvtECF7ZDkO2giAygPtLyxPT81drFuTmLRnqPJdWwy8Cl+B6cpx9g+ToD5 vTOSiyj8heDYlqbOzEeN6OqN1II4VnGzDk0WTo7Fjvxk6Yz2eZfQkA4aIaddET1x8YbW HYCf1NpmYC1R38hZa2eQN7T1zBT6YjhTsEeNq+CPUtGCsIAOxLLnB7HlnKrIvDsUl1xG chc+GSth/nHegEZejpPnY/BJHGnZa9gLNhoMmoQKgW/ugJEjssgyWSPh8i9AxuU3Whw8 /IcoQROBJKEPnulYGmVksKS74Fb7IiW8Mz7jFhtgBx8HwZDn8nq9/6GVD8qYMgxNzyYx ghAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=VJ2kBMQnTepOO13Yg4zjy23GC+GH4PK0ByMWiXCv1l0=; b=BFvBN5GK+cK/HrKfNSggfN42NXKqSeadKZ8Q3Eoq2DGObo0tAeY21HkBZP1VWY+Q0U 52oCIhzNoWth8EOz7Z5EQAeC4KFIdGnXZKNKmF0NTtsKlvf9doyhYitAqCK6qHl5WytV 5Xe21q5vvDcZK3qa1aNaMNBZXueBqO/MxOMrFd6Z1e2zQ9pIuceRWMuSyu6pBO+R74rG hQCGxSCpgKYtYUSSIRh6fyUi2ldAUayj5teP5yQz1RsXmtKzQiqkAytdQGGaDDt5z3qv ahDkFerQA9LIpGy8ge7SsV6BQQWnbWd19X8DSSckrQhGFQv4+lnzHVv2DxwoVtzoaRO1 CFGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=EelzAQi3; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a056a001ac800b00565a581ecc0si10921953pfv.11.2022.12.03.04.43.55; Sat, 03 Dec 2022 04:44:06 -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=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=EelzAQi3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229650AbiLCMTM (ORCPT + 82 others); Sat, 3 Dec 2022 07:19:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbiLCMTJ (ORCPT ); Sat, 3 Dec 2022 07:19:09 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEBF21D659 for ; Sat, 3 Dec 2022 04:19:08 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id vv4so17291789ejc.2 for ; Sat, 03 Dec 2022 04:19:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=VJ2kBMQnTepOO13Yg4zjy23GC+GH4PK0ByMWiXCv1l0=; b=EelzAQi3ycgYepqgRvsBBEs+oyuo1oGZME9colgRqhzm23WFvFS9xLfmZ8oRofI4T9 tG76KxqFYz67nxCILvi6RtIGKP9Y1mAooEB8cQcY9PAYt0IVg6NcyQ0qYKS7WgEgRsQe jLW7ZzdtpjL7iwQeN8jZOZ6MGHWYfCVTz+1Jr5CL4xp9LHnkh1Sx6e356qHRyRQ9QMjw j2GjAK844p3DdwnenZfa/u90h73CeajspKfPG88u4eOK4ePvYcAvA8h1ra1qe12w2EAA /iB35lWi++12T+9Y2PnnsmQVXr8D5ARFQNAXIWK/hCMYNOOfaQ8i3sU9tz4r+zZHqIgZ w2ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VJ2kBMQnTepOO13Yg4zjy23GC+GH4PK0ByMWiXCv1l0=; b=ZFj+GXEEeKnAOfHs1VGLZNNfTI5vuWN+nhr5nEkqoimVD0sTUoq+IOub+1FMJwJfGx a9YXTfRNWV2uwaoENpIOFfP89nZTQZtioAD+Y/A4a/Wq1GEGuWQDRQAN69EI4unwdWyi CcSiqPo60pQK6Xf83jQJXj89wG9OrF9m2iO6LRKDtans6zXkNHjNhMPU7cGYsQfqpxm9 isUKEosvJN+dC1wCihfXH9qRfNhvq8y+B9rkh7gydtRn1vtlvPoDPnoeO+ufFuvFhdWv C1y/wcc+1Qv2QT5ZEPTwfABu/yL5cFeK2ZTeaxu4n+VXRuHvZc4UgftX5ngCm1BOA8jh ylAA== X-Gm-Message-State: ANoB5pnHOGgJDevPjmHZju41N80ULoNODw9nUrx2tLub0EAFqlEb4Kz7 qplL426bu1l9TwaCL/UkD6SxezzgsglUEwufS4A7sA== X-Received: by 2002:a17:906:6dd5:b0:78d:a633:b55 with SMTP id j21-20020a1709066dd500b0078da6330b55mr66234095ejt.106.1670069947041; Sat, 03 Dec 2022 04:19:07 -0800 (PST) MIME-Version: 1.0 References: <20221128161424.608889-1-apatel@ventanamicro.com> <20221128161424.608889-9-apatel@ventanamicro.com> <20221129054616.4zju5z7ipg6wki7l@kamzik> In-Reply-To: <20221129054616.4zju5z7ipg6wki7l@kamzik> From: Anup Patel Date: Sat, 3 Dec 2022 17:48:54 +0530 Message-ID: Subject: Re: [PATCH 8/9] RISC-V: KVM: Add ONE_REG interface for mvendorid, marchid, and mimpid To: Andrew Jones Cc: Anup Patel , Paolo Bonzini , Atish Patra , Palmer Dabbelt , Paul Walmsley , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 29, 2022 at 11:16 AM Andrew Jones wrote: > > On Mon, Nov 28, 2022 at 09:44:23PM +0530, Anup Patel wrote: > > We add ONE_REG interface for VCPU mvendorid, marchid, and mimpid > > so that KVM user-space can change this details to support migration > > across heterogeneous hosts. > > > > Signed-off-by: Anup Patel > > --- > > arch/riscv/include/uapi/asm/kvm.h | 3 +++ > > arch/riscv/kvm/vcpu.c | 27 +++++++++++++++++++++++++++ > > 2 files changed, 30 insertions(+) > > > > diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h > > index 8985ff234c01..92af6f3f057c 100644 > > --- a/arch/riscv/include/uapi/asm/kvm.h > > +++ b/arch/riscv/include/uapi/asm/kvm.h > > @@ -49,6 +49,9 @@ struct kvm_sregs { > > struct kvm_riscv_config { > > unsigned long isa; > > unsigned long zicbom_block_size; > > + unsigned long mvendorid; > > + unsigned long marchid; > > + unsigned long mimpid; > > }; > > > > /* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ > > diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c > > index 312a8a926867..7c08567097f0 100644 > > --- a/arch/riscv/kvm/vcpu.c > > +++ b/arch/riscv/kvm/vcpu.c > > @@ -276,6 +276,15 @@ static int kvm_riscv_vcpu_get_reg_config(struct kvm_vcpu *vcpu, > > return -EINVAL; > > reg_val = riscv_cbom_block_size; > > break; > > + case KVM_REG_RISCV_CONFIG_REG(mvendorid): > > + reg_val = vcpu->arch.mvendorid; > > + break; > > + case KVM_REG_RISCV_CONFIG_REG(marchid): > > + reg_val = vcpu->arch.marchid; > > + break; > > + case KVM_REG_RISCV_CONFIG_REG(mimpid): > > + reg_val = vcpu->arch.mimpid; > > + break; > > default: > > return -EINVAL; > > } > > @@ -338,6 +347,24 @@ static int kvm_riscv_vcpu_set_reg_config(struct kvm_vcpu *vcpu, > > break; > > case KVM_REG_RISCV_CONFIG_REG(zicbom_block_size): > > return -EOPNOTSUPP; > > + case KVM_REG_RISCV_CONFIG_REG(mvendorid): > > + if (!vcpu->arch.ran_atleast_once) > > + vcpu->arch.mvendorid = reg_val; > > + else > > + return -EBUSY; > > + break; > > + case KVM_REG_RISCV_CONFIG_REG(marchid): > > + if (!vcpu->arch.ran_atleast_once) > > + vcpu->arch.marchid = reg_val; > > + else > > + return -EBUSY; > > + break; > > + case KVM_REG_RISCV_CONFIG_REG(mimpid): > > + if (!vcpu->arch.ran_atleast_once) > > + vcpu->arch.mimpid = reg_val; > > + else > > + return -EBUSY; > > + break; > > default: > > return -EINVAL; > > } > > -- > > 2.34.1 > > > > At some point we should patch Documentation/virt/kvm/api.rst to describe > the possible errors we have. It's missing EOPNOTSUPP and EBUSY. > > Also, I see a couple places were we use EOPNOTSUPP that would be better > as EBUSY. And finally I wonder if we shouldn't use ENOENT when the reg_num > is wrong/unknown, which would allow us to differentiate between bad > reg_num and bad reg_val in set-one ioctls. > > I can send an RFC series to better describe these thoughts. Sure, go ahead. > > And for this patch, > > Reviewed-by: Andrew Jones > > Thanks, > drew Regards, Anup