From: Roman Kagan Subject: Re: [PATCH v5 2/2] kvm: x86: hyperv: guest->host event signaling via eventfd Date: Wed, 13 Dec 2017 14:04:30 +0300 Message-ID: <20171213110428.GC18723@rkaganb.sw.ru> References: <20171212160742.793-1-rkagan@virtuozzo.com> <20171212160742.793-3-rkagan@virtuozzo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , "Denis V. Lunev" , Konrad Rzeszutek Wilk , Vitaly Kuznetsov To: David Hildenbrand Return-path: Received: from mail-db5eur01hn0240.outbound.protection.outlook.com ([104.47.2.240]:63048 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752708AbdLMLEs (ORCPT ); Wed, 13 Dec 2017 06:04:48 -0500 Content-Disposition: inline In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Dec 13, 2017 at 10:51:06AM +0100, David Hildenbrand wrote: > > +static u16 kvm_hvcall_signal_event(struct kvm_vcpu *vcpu, bool fast, u64 param) > > +{ > > + u16 ret; > > + u32 conn_id, flag_no; > > + int idx; > > + struct eventfd_ctx *eventfd; > > + > > + if (unlikely(!fast)) { > > + gpa_t gpa = param; > > + > > + if ((gpa & (__alignof__(param) - 1)) || > > + offset_in_page(gpa) + sizeof(param) > PAGE_SIZE) > > + return HV_STATUS_INVALID_ALIGNMENT; > > + > > + idx = srcu_read_lock(&vcpu->kvm->srcu); > > + ret = kvm_vcpu_read_guest(vcpu, gpa, ¶m, sizeof(param)); > > + srcu_read_unlock(&vcpu->kvm->srcu, idx); > > + > > + if (ret < 0) > > + return HV_STATUS_INSUFFICIENT_MEMORY; > > + } > > + > > + /* > > + * the signaled event number is made up of a 24bit "connection id" and > > + * a 16bit "flag number"; on the hypervisor side it's only their sum > > + * that matters > > + */ > > + conn_id = param; > > + flag_no = param >> 32; > > + if ((conn_id & ~KVM_HYPERV_CONN_ID_MASK) || (flag_no & 0xffff0000)) > > 1. You seem to check for RsvdZ here (flag_no & 0xffff0000), > "HV_STATUS_INVALID_CONNECTION_ID: The specified connection ID is > invalid." > -> Shouldn't the reserved field be simply ignored? It's "reserved zero", so I think it's correct to reject non-zero values. > 2. KVM_HYPERV_CONN_ID_MASK. "ConnectionId (4 bytes)". > > Why should it only be 3bytes? > > (I am pretty sure I am missing something in the document here :) ) "11.10.7 Connections Connections are identified by 32-bit IDs. The high 8 bits are reserved and must be zero.[...]" > > + return HV_STATUS_INVALID_CONNECTION_ID; > > + conn_id += flag_no; > > "FlagNumber specifies the relative index of the event flag that the > caller wants to set within the target" > > I am not sure if we should simply change the connection id here. This > seems to be an additional parameter to be passed to the one connection id. Right. I think I misinterpreted this part back when I implemented it in QEMU (first submission was this summer). We lived happily with that code, because the FlagNuber was always zero, and then I copied that over to this KVM patch. I think requiring it to be zero is a better choice; I've prepared v7 to that end. Thanks, Roman.