Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp328980ybg; Sun, 26 Jul 2020 06:00:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlNbY0Vy0ID9SYC+oXWxCeY7YiT0NAmkzXywOCfd+4Bbo2Af33lgAm3clMUsPiLmvBSuD1 X-Received: by 2002:a17:907:94cc:: with SMTP id dn12mr16453200ejc.223.1595768437426; Sun, 26 Jul 2020 06:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595768437; cv=none; d=google.com; s=arc-20160816; b=U8Q07Fcf7QxlyaT3AnY5hVN52XqdB9nH+TkX+nqKXh7hc36XgQvm0QxzkzzYMF0eF6 oySwZ+A7Y5ICLO2VYuBM/264WBbOJVybLo/5S2BE0DkfZEb7dPzu1vnPBC2ocyZKEZSA Plj37GxJTAA8uNK99yZ9LZMJwVwzM0hk6ctVVmGTN3XDTCWBFpY1/6jhFK/MYILD5mbA MQpMhvhiipB4IMHqvAHlnJ7AQ8rKXKyN1b/uSb2K/sKva16nYr0IRcTdKOUHjCHdrtVB gZ0Er9b+bjqjn0UBwhZ4+swm+pvssOV4OHN3Ttn8mcutkMOeeo6+on0dVDxx5nyafF6W TCog== 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=aJ0QTk1kAr2FXG3tNKxMDTj3E6xC0tBqD5CEm/p3JFE=; b=edgQqmEo6tGt/J/RFml4ALWdEmrhnO+EuLJR1ROpZw7kuptw2sydwBht6kakmig7cw QGlvcO70yRJu8sz6Bu9Ay1f5V9//fhMdwjqcajDuQ7HIcKaMDJ8F+xnKcX4FMBzZr9Ue Uc22XkpKVx3U1h9I9wWqgqNLFd7zEdulEW4UstNwK3c6z98zztu4l4JdAHjLPwpCSTlk 1w1qbYtKtH1xwgPpwfy6ORtiNeokzqI7LY0yHtfUUyqc8xWqjnRizIGcn+Q/6L/xphUx F141VEevfoapcw+3tnu6cC9YXw/3DEptuqdmqir3hPqVQqCMqM6XGRZlcU7PpjGx6tyg 43/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=e3qylBuP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g18si3871214ejp.681.2020.07.26.06.00.14; Sun, 26 Jul 2020 06:00:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=e3qylBuP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726455AbgGZM7K (ORCPT + 99 others); Sun, 26 Jul 2020 08:59:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727894AbgGZM7K (ORCPT ); Sun, 26 Jul 2020 08:59:10 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2F43C0619D4 for ; Sun, 26 Jul 2020 05:59:09 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id y3so12256883wrl.4 for ; Sun, 26 Jul 2020 05:59:09 -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=aJ0QTk1kAr2FXG3tNKxMDTj3E6xC0tBqD5CEm/p3JFE=; b=e3qylBuPPyd36kYi09rS61kEhLJtEb/XiQOym4M3xymiMBeoHEsRYf7Cl7PEyEpyzg c6RjEdgiKjPRk80f99amxldvIWn8kAn2HrIK+4WB97VzHtKsfAq4IidLgJqkLaPb8vf2 lgOrGq2sfuOHdd2NQeeywpEG7BhiYWAOtFlnHV9PhGwA855BfYE19uhn8Cud4Mvvd23l pKb4vFdCWBWOzwXwFnKBv/Wod/PlT0wyvHouPqYCoQQpUfqTUYylmYyoq5AYUZC3dbBp LxEonSSWb6BKqUxWs+cLg65BjTqzXH6n5wq0JqZqrEzIBxAzVyPpSfVirsjtlJylWK0p 256A== 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=aJ0QTk1kAr2FXG3tNKxMDTj3E6xC0tBqD5CEm/p3JFE=; b=iQNqNChuKUe9ZDAKPXLzAvLvwHN1WvsCaAs3l5tSKTGZUdGSoUoKSgr0uxr9t/RGia PG4mMr9ou8dZ+wSrA5hv8IhUL1xwQ7bPk/Wvp5etQi5GxipGdOEoios4YaAB57wK6CCH jx5httsKNKr23Qu9HKffbqxY331Xc16jdGHrwSWghUl5SSTeeLFAxTUF3/MQjx+4KHfp 5nzdRqydIwuuWQldr90iMZ97N9+FQJ0hqfppoSDWgO09xQQB86EQ0V1UIowIcvsCKK09 nHVSr3hg9efXmx3fo4jrzl7/+fd/3kvoaj50OqVMRU7XnDLAnExyB/7VR/NilQQ81yXu 5hJA== X-Gm-Message-State: AOAM5304hj2L9KCEfX7aFQYUQZF9MZ5qscx8xqXhz19ltFS0/6ijTxo4 /tOjrhzoXC8HRGoewGS4Fzz8TvVEBOq7Y8fyXxtdCPpJ X-Received: by 2002:adf:f186:: with SMTP id h6mr16468220wro.144.1595768348627; Sun, 26 Jul 2020 05:59:08 -0700 (PDT) MIME-Version: 1.0 References: <20200724085441.1514-1-jiangyifei@huawei.com> <20200724085441.1514-3-jiangyifei@huawei.com> In-Reply-To: <20200724085441.1514-3-jiangyifei@huawei.com> From: Anup Patel Date: Sun, 26 Jul 2020 18:28:57 +0530 Message-ID: Subject: Re: [RFC 2/2] RISC-V: KVM: read\write kernel mmio device support To: Yifei Jiang Cc: Paolo Bonzini , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra , KVM General , kvm-riscv@lists.infradead.org, linux-riscv , "linux-kernel@vger.kernel.org List" , "Zhangxiaofeng (F)" , wu.wubin@huawei.com, Zhanghailiang , "dengkai (A)" , limingwang@huawei.com 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 Change subject to: RISC-V: KVM: kernel mmio read/write support Also add 1-2 sentences of commit description. On Fri, Jul 24, 2020 at 2:25 PM Yifei Jiang wrote: > > Signed-off-by: Yifei Jiang > Signed-off-by: Mingwang Li > --- > arch/riscv/kvm/vcpu_exit.c | 38 ++++++++++++++++++++++++++++++++------ > 1 file changed, 32 insertions(+), 6 deletions(-) > > diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c > index e97ba96cb0ae..448f11179fa8 100644 > --- a/arch/riscv/kvm/vcpu_exit.c > +++ b/arch/riscv/kvm/vcpu_exit.c > @@ -191,6 +191,8 @@ static int virtual_inst_fault(struct kvm_vcpu *vcpu, struct kvm_run *run, > static int emulate_load(struct kvm_vcpu *vcpu, struct kvm_run *run, > unsigned long fault_addr, unsigned long htinst) > { > + int ret; > + u8 data_buf[8]; > unsigned long insn; > int shift = 0, len = 0; > struct kvm_cpu_trap utrap = { 0 }; > @@ -272,19 +274,32 @@ static int emulate_load(struct kvm_vcpu *vcpu, struct kvm_run *run, > vcpu->arch.mmio_decode.len = len; > vcpu->arch.mmio_decode.return_handled = 0; > > - /* Exit to userspace for MMIO emulation */ > - vcpu->stat.mmio_exit_user++; > - run->exit_reason = KVM_EXIT_MMIO; > + ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, fault_addr, len, > + data_buf); > + > run->mmio.is_write = false; > run->mmio.phys_addr = fault_addr; > run->mmio.len = len; > > + if (!ret) { > + /* We handled the access successfully in the kernel. */ > + memcpy(run->mmio.data, data_buf, len); > + vcpu->stat.mmio_exit_kernel++; > + kvm_riscv_vcpu_mmio_return(vcpu, run); > + return 1; > + } > + > + /* Exit to userspace for MMIO emulation */ > + vcpu->stat.mmio_exit_user++; > + run->exit_reason = KVM_EXIT_MMIO; > + > return 0; > } > > static int emulate_store(struct kvm_vcpu *vcpu, struct kvm_run *run, > unsigned long fault_addr, unsigned long htinst) > { > + int ret; > u8 data8; > u16 data16; > u32 data32; > @@ -378,13 +393,24 @@ static int emulate_store(struct kvm_vcpu *vcpu, struct kvm_run *run, > return -ENOTSUPP; > }; > > - /* Exit to userspace for MMIO emulation */ > - vcpu->stat.mmio_exit_user++; > - run->exit_reason = KVM_EXIT_MMIO; > + ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, fault_addr, len, > + run->mmio.data); > + > run->mmio.is_write = true; > run->mmio.phys_addr = fault_addr; > run->mmio.len = len; > > + if (!ret) { > + /* We handled the access successfully in the kernel. */ > + vcpu->stat.mmio_exit_kernel++; > + kvm_riscv_vcpu_mmio_return(vcpu, run); > + return 1; > + } > + > + /* Exit to userspace for MMIO emulation */ > + vcpu->stat.mmio_exit_user++; > + run->exit_reason = KVM_EXIT_MMIO; > + > return 0; > } > > -- > 2.19.1 > > Regards, Anup