From: Andrew Jones <ajones@ventanamicro.com>
To: Anup Patel <anup@brainfault.org>
Cc: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org, paul.walmsley@sifive.com,
palmer@dabbelt.com, aou@eecs.berkeley.edu,
mchitale@ventanamicro.com, heiko@sntech.de
Subject: Re: [PATCH 3/4] riscv: KVM: Apply insn-def to hfence encodings
Date: Mon, 29 Aug 2022 11:47:39 +0200 [thread overview]
Message-ID: <20220829094739.pn7iltmtimpwpshf@kamzik> (raw)
In-Reply-To: <CAAhSdy0d8mjr5-5Um2DpLgnhPb3UnGggXvbu_=oqEHWYzMP1SQ@mail.gmail.com>
On Mon, Aug 29, 2022 at 02:07:59PM +0530, Anup Patel wrote:
> On Fri, Aug 19, 2022 at 7:32 PM Andrew Jones <ajones@ventanamicro.com> wrote:
> >
> > Introduce hfence instruction encodings and apply them to KVM's use.
> > With the self-documenting nature of the instruction encoding macros,
> > and a spec always within arm's reach, it's safe to remove the
> > comments, so we do that too.
> >
> > Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
> > ---
> > arch/riscv/include/asm/insn-def.h | 8 ++
> > arch/riscv/kvm/tlb.c | 117 ++++--------------------------
> > 2 files changed, 21 insertions(+), 104 deletions(-)
> >
> > diff --git a/arch/riscv/include/asm/insn-def.h b/arch/riscv/include/asm/insn-def.h
> > index 4cd0208068dd..cd1c0d365f47 100644
> > --- a/arch/riscv/include/asm/insn-def.h
> > +++ b/arch/riscv/include/asm/insn-def.h
> > @@ -79,4 +79,12 @@
> > #define RS1(v) __REG(v)
> > #define RS2(v) __REG(v)
> >
> > +#define OPCODE_SYSTEM OPCODE(115)
> > +
> > +#define HFENCE_VVMA(vaddr, asid) \
> > + INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(17), RD(0), vaddr, asid)
> > +
> > +#define HFENCE_GVMA(gaddr, vmid) \
> > + INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(49), RD(0), gaddr, vmid)
> > +
> > #endif /* __ASM_INSN_DEF_H */
> > diff --git a/arch/riscv/kvm/tlb.c b/arch/riscv/kvm/tlb.c
> > index 1a76d0b1907d..f742a0d888e1 100644
> > --- a/arch/riscv/kvm/tlb.c
> > +++ b/arch/riscv/kvm/tlb.c
> > @@ -12,22 +12,7 @@
> > #include <linux/kvm_host.h>
> > #include <asm/cacheflush.h>
> > #include <asm/csr.h>
> > -
> > -/*
> > - * Instruction encoding of hfence.gvma is:
> > - * HFENCE.GVMA rs1, rs2
> > - * HFENCE.GVMA zero, rs2
> > - * HFENCE.GVMA rs1
> > - * HFENCE.GVMA
> > - *
> > - * rs1!=zero and rs2!=zero ==> HFENCE.GVMA rs1, rs2
> > - * rs1==zero and rs2!=zero ==> HFENCE.GVMA zero, rs2
> > - * rs1!=zero and rs2==zero ==> HFENCE.GVMA rs1
> > - * rs1==zero and rs2==zero ==> HFENCE.GVMA
> > - *
> > - * Instruction encoding of HFENCE.GVMA is:
> > - * 0110001 rs2(5) rs1(5) 000 00000 1110011
> > - */
> > +#include <asm/insn-def.h>
> >
> > void kvm_riscv_local_hfence_gvma_vmid_gpa(unsigned long vmid,
> > gpa_t gpa, gpa_t gpsz,
> > @@ -41,31 +26,14 @@ void kvm_riscv_local_hfence_gvma_vmid_gpa(unsigned long vmid,
> > }
> >
> > for (pos = gpa; pos < (gpa + gpsz); pos += BIT(order)) {
> > - /*
> > - * rs1 = a0 (GPA >> 2)
> > - * rs2 = a1 (VMID)
> > - * HFENCE.GVMA a0, a1
> > - * 0110001 01011 01010 000 00000 1110011
> > - */
> > - asm volatile ("srli a0, %0, 2\n"
> > - "add a1, %1, zero\n"
> > - ".word 0x62b50073\n"
> > - :: "r" (pos), "r" (vmid)
> > - : "a0", "a1", "memory");
> > + asm volatile (HFENCE_GVMA("%0", "%1")
Thank you for the review, Anup! I'd also like to get opinions on whether
the caller should quote the register tokens or the call should be made as,
e.g. HFENCE_GVMA(%0, %1), and then do the quoting inside the macro for
C callers. I could go either way, but I'm starting to lean towards moving
the quoting into the macros.
Thanks,
drew
next prev parent reply other threads:[~2022-08-29 9:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-19 14:02 [PATCH 0/4] riscv: Introduce support for defining instructions Andrew Jones
2022-08-19 14:02 ` [PATCH 1/4] riscv: Add X register names to gpr-nums Andrew Jones
2022-08-29 8:24 ` Anup Patel
2022-08-19 14:02 ` [PATCH 2/4] riscv: Introduce support for defining instructions Andrew Jones
2022-08-19 14:26 ` Andrew Jones
2022-08-29 8:31 ` Anup Patel
2022-08-19 14:02 ` [PATCH 3/4] riscv: KVM: Apply insn-def to hfence encodings Andrew Jones
2022-08-29 8:37 ` Anup Patel
2022-08-29 9:47 ` Andrew Jones [this message]
2022-08-30 3:12 ` Anup Patel
2022-08-19 14:02 ` [PATCH 4/4] riscv: KVM: Apply insn-def to hlv encodings Andrew Jones
2022-08-29 8:44 ` Anup Patel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220829094739.pn7iltmtimpwpshf@kamzik \
--to=ajones@ventanamicro.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=heiko@sntech.de \
--cc=kvm-riscv@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mchitale@ventanamicro.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®