Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2241186rwd; Fri, 16 Jun 2023 00:53:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7zZX8WdrkO4jqAUUgxUfhgmuzDIv00ieEGI9j1a8Zsnm7N4riZMvPI0+UmohJhZ9ipINcA X-Received: by 2002:a17:90a:aa12:b0:25e:9e41:34b0 with SMTP id k18-20020a17090aaa1200b0025e9e4134b0mr1019105pjq.0.1686901992504; Fri, 16 Jun 2023 00:53:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686901992; cv=none; d=google.com; s=arc-20160816; b=wOUl+ldtYFQkfG2OxL0oue7fzkG/Jh79kzOGU69DuFUyhZmdsJ4AjIOqCNoyspKtf0 u/lFEoy+gdEu0VOHBtww22ykIf7CWfzMEh4T79+g4qVdwewNtecR43puQ69Fe4Z9miK0 6tD16j4K7w37fj84m2aywckEmyGzQ3llqyuK3pJiHmlI8Mdu4Fk10mGwfL6/ELos7Gi0 63tfesuJvGN3NsOu5hKgMHSDXlmQTlyXb206XMU0gARneTD/bEYr+lblRl260H3QjOlQ szQDSPBCSe/aSGDzJF87kymnSugLIAGxhhEeAfCELGefnOtV5vnKjNpXh1yizEXV6BD/ bvBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=H1j80AwpMkKggqs8JmwcVb7r4+TSqY0M2+PEoCgbGaQ=; b=m40RQaqXiYmAHc4YzVXfBCbT679gLbpqYywcaxRGInufMH5VJveZFHvsK0FgkJT4F5 X/gI6n+P0rIb3XJcETGwh3utN7Nflxv9tr/D/J4OU+f9M/EwCoGeR/B8TS9tHafiwHck XRVw69vY6LSIlPVtE+W9WeNjQVMBLNySKv3ImoZtlOUW0lI/l0zhIje+EQAbWdT+sFjs xtlg8qyzL4JvxRowgzN/eu3ndMQJguD9HQ+vTRuawXpek3wy4Oj+HyynB9tNIOdeiyB8 2/2jdTMqDQURNLr2nRv61kQAt25eG9epRCUtkWmxzQ0o3avPyi/vXBYePv38Dk2aptSK Rfww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=n0rkyQFp; 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 q90-20020a17090a4fe300b0025c095abe89si1080258pjh.56.2023.06.16.00.52.58; Fri, 16 Jun 2023 00:53:12 -0700 (PDT) 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=@atishpatra.org header.s=google header.b=n0rkyQFp; 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 S245088AbjFPHfP (ORCPT + 99 others); Fri, 16 Jun 2023 03:35:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245364AbjFPHfN (ORCPT ); Fri, 16 Jun 2023 03:35:13 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1345A10F7 for ; Fri, 16 Jun 2023 00:35:12 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4f62cf9755eso427630e87.1 for ; Fri, 16 Jun 2023 00:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; t=1686900910; x=1689492910; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=H1j80AwpMkKggqs8JmwcVb7r4+TSqY0M2+PEoCgbGaQ=; b=n0rkyQFpCrFkjxi0k33DMxWY76a+6oC/tXuVgF+FlA8I0dNziZl/JDIpP2nnqsZYdY l0JOGFvRuH2bjtBD97WxDf5ULr8yVdelWn4de0sZZWAZhLhdoXIWFBpicP5sznM4mZ1m kE49OQ06Briwnh2HhBWzThEXw4wIo9O2nRZrI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686900910; x=1689492910; h=content-transfer-encoding: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=H1j80AwpMkKggqs8JmwcVb7r4+TSqY0M2+PEoCgbGaQ=; b=efU84VM7+KIP+KNAVCZfoL+Ox2w2GWhdGPSENqV8i9dA5l/NJJGG6b4r1QUYiyz7QS rwcqqIxlVi0azU9bCHdLltUu3wRb+W/GRwUfQJrOBRLkLj+kloe1EW/u/jayiG8xXrJx iY5Z/QO4sBfhNCOooSbGc9OyO14D4ZIJusHCiDOyJKd2q1qm8S477EKskA4CkYiTBYgx Js5OEDZqQyg33hT3D2NzjQ9qSNdYDEZcn0C2BjGBdV5K9sCgUoi7i6mimfNQsvKxPdWr ddfqhhdrqJfxQBu6jDPHAZ3MoK6AMipRTsVrXuPV2tddib9LIzUKXP1e8n3kLqqyAigd fAnA== X-Gm-Message-State: AC+VfDzU1Umqkvzuf8AnreFXmPkAk8Bi0oItYMi4rEh4HGb9njzA+SUr hUgE3mZePboxNYhbgmp+WSZcHRP52DrsZjB6nago X-Received: by 2002:a2e:980a:0:b0:2b3:356c:94d6 with SMTP id a10-20020a2e980a000000b002b3356c94d6mr888795ljj.16.1686900910233; Fri, 16 Jun 2023 00:35:10 -0700 (PDT) MIME-Version: 1.0 References: <20230615073353.85435-1-apatel@ventanamicro.com> <20230615073353.85435-9-apatel@ventanamicro.com> In-Reply-To: <20230615073353.85435-9-apatel@ventanamicro.com> From: Atish Patra Date: Fri, 16 Jun 2023 00:34:58 -0700 Message-ID: Subject: Re: [PATCH v3 08/10] RISC-V: KVM: Expose APLIC registers as attributes of AIA irqchip To: Anup Patel Cc: Paolo Bonzini , Palmer Dabbelt , Paul Walmsley , Andrew Jones , 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" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Thu, Jun 15, 2023 at 12:34=E2=80=AFAM Anup Patel wrote: > > We expose APLIC registers as KVM device attributes of the in-kernel > AIA irqchip device. This will allow KVM user-space to save/restore > APLIC state using KVM device ioctls(). > > Signed-off-by: Anup Patel > --- > arch/riscv/include/asm/kvm_aia.h | 3 +++ > arch/riscv/include/uapi/asm/kvm.h | 6 +++++ > arch/riscv/kvm/aia_aplic.c | 43 +++++++++++++++++++++++++++++++ > arch/riscv/kvm/aia_device.c | 25 ++++++++++++++++++ > 4 files changed, 77 insertions(+) > > diff --git a/arch/riscv/include/asm/kvm_aia.h b/arch/riscv/include/asm/kv= m_aia.h > index f6bd8523395f..ba939c0054aa 100644 > --- a/arch/riscv/include/asm/kvm_aia.h > +++ b/arch/riscv/include/asm/kvm_aia.h > @@ -129,6 +129,9 @@ static inline void kvm_riscv_vcpu_aia_imsic_cleanup(s= truct kvm_vcpu *vcpu) > { > } > > +int kvm_riscv_aia_aplic_set_attr(struct kvm *kvm, unsigned long type, u3= 2 v); > +int kvm_riscv_aia_aplic_get_attr(struct kvm *kvm, unsigned long type, u3= 2 *v); > +int kvm_riscv_aia_aplic_has_attr(struct kvm *kvm, unsigned long type); > int kvm_riscv_aia_aplic_inject(struct kvm *kvm, u32 source, bool level); > int kvm_riscv_aia_aplic_init(struct kvm *kvm); > void kvm_riscv_aia_aplic_cleanup(struct kvm *kvm); > diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/= asm/kvm.h > index 047c8fc5bd71..9ed822fc5589 100644 > --- a/arch/riscv/include/uapi/asm/kvm.h > +++ b/arch/riscv/include/uapi/asm/kvm.h > @@ -249,6 +249,12 @@ enum KVM_RISCV_SBI_EXT_ID { > #define KVM_DEV_RISCV_AIA_GRP_CTRL 2 > #define KVM_DEV_RISCV_AIA_CTRL_INIT 0 > > +/* > + * The device attribute type contains the memory mapped offset of the > + * APLIC register (range 0x0000-0x3FFF) and it must be 4-byte aligned. > + */ > +#define KVM_DEV_RISCV_AIA_GRP_APLIC 3 > + > /* One single KVM irqchip, ie. the AIA */ > #define KVM_NR_IRQCHIPS 1 > > diff --git a/arch/riscv/kvm/aia_aplic.c b/arch/riscv/kvm/aia_aplic.c > index eecd8f4abe21..39e72aa016a4 100644 > --- a/arch/riscv/kvm/aia_aplic.c > +++ b/arch/riscv/kvm/aia_aplic.c > @@ -501,6 +501,49 @@ static struct kvm_io_device_ops aplic_iodoev_ops =3D= { > .write =3D aplic_mmio_write, > }; > > +int kvm_riscv_aia_aplic_set_attr(struct kvm *kvm, unsigned long type, u3= 2 v) > +{ > + int rc; > + > + if (!kvm->arch.aia.aplic_state) > + return -ENODEV; > + > + rc =3D aplic_mmio_write_offset(kvm, type, v); > + if (rc) > + return rc; > + > + return 0; > +} > + > +int kvm_riscv_aia_aplic_get_attr(struct kvm *kvm, unsigned long type, u3= 2 *v) > +{ > + int rc; > + > + if (!kvm->arch.aia.aplic_state) > + return -ENODEV; > + > + rc =3D aplic_mmio_read_offset(kvm, type, v); > + if (rc) > + return rc; > + > + return 0; > +} > + > +int kvm_riscv_aia_aplic_has_attr(struct kvm *kvm, unsigned long type) > +{ > + int rc; > + u32 val; > + > + if (!kvm->arch.aia.aplic_state) > + return -ENODEV; > + > + rc =3D aplic_mmio_read_offset(kvm, type, &val); > + if (rc) > + return rc; > + > + return 0; > +} > + > int kvm_riscv_aia_aplic_init(struct kvm *kvm) > { > int i, ret =3D 0; > diff --git a/arch/riscv/kvm/aia_device.c b/arch/riscv/kvm/aia_device.c > index 7ab555121872..c649ad6e8e0a 100644 > --- a/arch/riscv/kvm/aia_device.c > +++ b/arch/riscv/kvm/aia_device.c > @@ -365,6 +365,15 @@ static int aia_set_attr(struct kvm_device *dev, stru= ct kvm_device_attr *attr) > break; > } > > + break; > + case KVM_DEV_RISCV_AIA_GRP_APLIC: > + if (copy_from_user(&nr, uaddr, sizeof(nr))) > + return -EFAULT; > + > + mutex_lock(&dev->kvm->lock); > + r =3D kvm_riscv_aia_aplic_set_attr(dev->kvm, type, nr); > + mutex_unlock(&dev->kvm->lock); > + > break; > } > > @@ -412,6 +421,20 @@ static int aia_get_attr(struct kvm_device *dev, stru= ct kvm_device_attr *attr) > if (copy_to_user(uaddr, &addr, sizeof(addr))) > return -EFAULT; > > + break; > + case KVM_DEV_RISCV_AIA_GRP_APLIC: > + if (copy_from_user(&nr, uaddr, sizeof(nr))) > + return -EFAULT; > + > + mutex_lock(&dev->kvm->lock); > + r =3D kvm_riscv_aia_aplic_get_attr(dev->kvm, type, &nr); > + mutex_unlock(&dev->kvm->lock); > + if (r) > + return r; > + > + if (copy_to_user(uaddr, &nr, sizeof(nr))) > + return -EFAULT; > + > break; > } > > @@ -448,6 +471,8 @@ static int aia_has_attr(struct kvm_device *dev, struc= t kvm_device_attr *attr) > return 0; > } > break; > + case KVM_DEV_RISCV_AIA_GRP_APLIC: > + return kvm_riscv_aia_aplic_has_attr(dev->kvm, attr->attr)= ; > } > > return -ENXIO; > -- > 2.34.1 > Reviewed-by: Atish Patra --=20 Regards, Atish