Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp833156ybn; Tue, 24 Sep 2019 10:11:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzBnJo9h4ZlvmiN3vGqzkR1dqnC8RmLigJ8yrW+RamBZd+cHyGguHENBE5jA6V3X2nuyqks X-Received: by 2002:adf:e488:: with SMTP id i8mr3667304wrm.20.1569345068595; Tue, 24 Sep 2019 10:11:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569345068; cv=none; d=google.com; s=arc-20160816; b=tpQ1/v22y5WOw5fLgGI7VmUAY0v5SZP2Ef2N2csQKVi1XMa5Djdmm1RmlPPpGppl0w aEEqcXo8SZtSp7ukrJ52ijGyJLvG4jeqIlPQ+9IsMXMvtLSuiwipd7lZjqIZqQi4kJV/ bWd8Y1LdcXCXamYi2IkKIHnKNx+Fu27/3S2BdDPGkVZFXHfCzSs8aI4IQWv6XqL8N4RD pqSYFUg+4N72/XwXcVqWIScIrUwwApBvKNyffU8w+Z8qb0Fi5YSZn4SCl/PXqWoItmDJ UpQeWB7V/qXtsrSnlw+UajfQgeDp0cbZYo65NR2f3QkpiNh78HElt0hpkhGoKyJVKGcB z5Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=POQzEF32pJw+JcJGYwatIQLE1EclVL51HgsgtLA7Qmw=; b=mw/cYdQMAusOjc6L92B8tX8ve+IuGQdfDU9KFlbt/L2PyfA75wMgGs6vYsVfi3xc4V tBYSVFI3RmIjNHGTvDyENYAbGTZuCsPyQquIuZAm6e19X0DLD2iNDO+fi7rkHxr0S1tB lNGdfbv6vbeR+c6jltJBtjObkAGoNN4vgmYln3c6JjN7qZ4NZLENy+7+oV5nbWcrUm1R +OFBoocZZObQ8/dKwYV+onNzPr/D4Uw4/FbpEUDSk5N2e344qpDXld3HaaGVicwkPKyt D6j/IDSXP2Crd7ycK1llGqVka+VjXHwag4dRChTqbjmzq8mnHeBSHGl16XE/SEI+EyV1 WMNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=BX0d9fUZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g32si1509520eda.330.2019.09.24.10.10.45; Tue, 24 Sep 2019 10:11:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=BX0d9fUZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407038AbfIWNJ5 (ORCPT + 99 others); Mon, 23 Sep 2019 09:09:57 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52768 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405137AbfIWNJ5 (ORCPT ); Mon, 23 Sep 2019 09:09:57 -0400 Received: by mail-wm1-f68.google.com with SMTP id x2so9889111wmj.2 for ; Mon, 23 Sep 2019 06:09:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=POQzEF32pJw+JcJGYwatIQLE1EclVL51HgsgtLA7Qmw=; b=BX0d9fUZ89UyQbARi+EIiuQz7/skB03FkmvzPaRZR3ZECUUjvMHRyuchQCs+a9LAea 2G+PIK23wzO+ITkoV9HFRLsgbyKRheMT1vim2zYSLgpWoWWc768/w/OGIxA96QWxNPvq SJEKRVfFuMmfOJ4unliQJ5+TqqUvYFiIxrGMrgtRcVF3bmfjsXCvhjEXGeLH1u++HYAe qbVfRinf3ErfTk1H3EIgzb+9pP38kcbHr+3YQCq6Js11GuGfHHbjTYGjPwlL63q3Y4/U SKvhbtyKQWs8UXSHYGStv9Jl55kLNR8viy0MdL8sHCwy11YhD12ccd5rFMgoUxtK2ykE sItA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=POQzEF32pJw+JcJGYwatIQLE1EclVL51HgsgtLA7Qmw=; b=T816TnvJu4EZfqFd110PCG7DwnktRAB8SDiQvto7+LRdA/9L4NZhoxjM9RSnYLla55 sMtmzFKoOCHX//57oakkhj1j1VSJjyR8ou2Pq1vR0zPhF71/xAxkPKFJaUVLSUt45yWT Ol5vlzdG6v5T+zYdQN2XoVYYf/qXkmEvDKUkkvn+5AaJMEP8dAepNWc5EooO1F11L84n XuQdBu8YqhFd8mpAefvvawsdmU2e6HyRKRHW2ijblC39v/qDQEu12J+D/PgXDbRHEBpp In3wEeuf+HuggnQ0unYc3JPLykB0NuDWG0EjOWFKolU8MpzuWndu/gb/R9V+Z0G8zFQ8 acMQ== X-Gm-Message-State: APjAAAXDaPUbpw8R/+JZWCnA82uR5KecwMsPetvV5F8Bpys+uxy+yGnL lYSut32zn4j9SIVxJiJVzehmjxsNnAyJii07Bs2yyA== X-Received: by 2002:a7b:c84f:: with SMTP id c15mr12094316wml.52.1569244194712; Mon, 23 Sep 2019 06:09:54 -0700 (PDT) MIME-Version: 1.0 References: <20190904161245.111924-1-anup.patel@wdc.com> <20190904161245.111924-12-anup.patel@wdc.com> <8c44ac8a-3fdc-b9dd-1815-06e86cb73047@redhat.com> In-Reply-To: <8c44ac8a-3fdc-b9dd-1815-06e86cb73047@redhat.com> From: Anup Patel Date: Mon, 23 Sep 2019 18:39:43 +0530 Message-ID: Subject: Re: [PATCH v7 10/21] RISC-V: KVM: Handle MMIO exits for VCPU To: Paolo Bonzini Cc: Anup Patel , Palmer Dabbelt , Paul Walmsley , Radim K , Daniel Lezcano , Thomas Gleixner , Alexander Graf , Atish Patra , Alistair Francis , Damien Le Moal , Christoph Hellwig , "kvm@vger.kernel.org" , "linux-riscv@lists.infradead.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 23, 2019 at 4:42 PM Paolo Bonzini wrote: > > On 04/09/19 18:15, Anup Patel wrote: > > + unsigned long guest_sstatus = > > + vcpu->arch.guest_context.sstatus | SR_MXR; > > + unsigned long guest_hstatus = > > + vcpu->arch.guest_context.hstatus | HSTATUS_SPRV; > > + unsigned long guest_vsstatus, old_stvec, tmp; > > + > > + guest_sstatus = csr_swap(CSR_SSTATUS, guest_sstatus); > > + old_stvec = csr_swap(CSR_STVEC, (ulong)&__kvm_riscv_unpriv_trap); > > + > > + if (read_insn) { > > + guest_vsstatus = csr_read_set(CSR_VSSTATUS, SR_MXR); > > Is this needed? IIUC SSTATUS.MXR encompasses a wider set of permissions: > > The HS-level MXR bit makes any executable page readable. {\tt > vsstatus}.MXR makes readable those pages marked executable at the VS > translation level, but only if readable at the guest-physical > translation level. > > So it should be enough to set SSTATUS.MXR=1 I think. But you also > shouldn't set SSTATUS.MXR=1 in the !read_insn case. I was being overly cautious here. Initially, I thought SSTATUS.MXR applies only to Stage2 and VSSTATUS.MXR applies only to Stage1. I agree with you. The HS-mode should only need to set SSTATUS.MXR. > > Also, you can drop the irq save/restore (which is already a save/restore > of SSTATUS) since you already write 0 to SSTATUS.SIE in your csr_swap. > Perhaps add a BUG_ON(guest_sstatus & SR_SIE) before the csr_swap? I had already dropped irq save/restore in v7 series and having BUG_ON() on guest_sstatus here would be better. > > > + asm volatile ("\n" > > + "csrrw %[hstatus], " STR(CSR_HSTATUS) ", %[hstatus]\n" > > + "li %[tilen], 4\n" > > + "li %[tscause], 0\n" > > + "lhu %[val], (%[addr])\n" > > + "andi %[tmp], %[val], 3\n" > > + "addi %[tmp], %[tmp], -3\n" > > + "bne %[tmp], zero, 2f\n" > > + "lhu %[tmp], 2(%[addr])\n" > > + "sll %[tmp], %[tmp], 16\n" > > + "add %[val], %[val], %[tmp]\n" > > + "2: csrw " STR(CSR_HSTATUS) ", %[hstatus]" > > + : [hstatus] "+&r"(guest_hstatus), [val] "=&r" (val), > > + [tmp] "=&r" (tmp), [tilen] "+&r" (tilen), > > + [tscause] "+&r" (tscause) > > + : [addr] "r" (addr)); > > + csr_write(CSR_VSSTATUS, guest_vsstatus); > > > > > +#ifndef CONFIG_RISCV_ISA_C > > + "li %[tilen], 4\n" > > +#else > > + "li %[tilen], 2\n" > > +#endif > > Can you use an assembler directive to force using a non-compressed > format for ld and lw? This would get rid of tilen, which is costing 6 > bytes (if I did the RVC math right) in order to save two. :) I tried looking for it but could not find any assembler directive to selectively turn-off instruction compression. > > Paolo > > > + "li %[tscause], 0\n" > > +#ifdef CONFIG_64BIT > > + "ld %[val], (%[addr])\n" > > +#else > > + "lw %[val], (%[addr])\n" > > +#endif Regards, Anup