From patchwork Mon May 9 13:15:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9046671 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0EA429F30C for ; Mon, 9 May 2016 13:18:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 17D2B200FF for ; Mon, 9 May 2016 13:18:26 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B41DA200F3 for ; Mon, 9 May 2016 13:18:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1azl2P-0006Ls-H2; Mon, 09 May 2016 13:15:53 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1azl2O-0006L5-7t for xen-devel@lists.xen.org; Mon, 09 May 2016 13:15:52 +0000 Received: from [193.109.254.147] by server-13.bemta-14.messagelabs.com id 3A/ED-02833-78D80375; Mon, 09 May 2016 13:15:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNIsWRWlGSWpSXmKPExsXitHSDvW57r0G 4wcXbjBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8blf49ZCh7JV6za3sjewPhKrIuRg0NCwF/i 8wfrLkZODjYBfYndLz4xgdgiAuoSpzsusoLYzAJ5Ep0fP7KD2MICGRKHX/exgNgsAioSxzbOB 6vnFfCU+HNoGlhcQkBO4vzxn8wgNqeAl8TcrpNgcSGgmpNH9zBD2GoS1/ovsUP0CkqcnPmEBW KXhMTBFy+YIU7jlvjbbT+BkW8WkqpZSKoWMDKtYtQoTi0qSy3SNTTSSyrKTM8oyU3MzNE1NDT Ry00tLk5MT81JTCrWS87P3cQIDCgGINjBeHaa8yFGSQ4mJVFeV0a9cCG+pPyUyozE4oz4otKc 1OJDjDIcHEoSvA+6DcKFBItS01Mr0jJzgKENk5bg4FES4f0BkuYtLkjMLc5Mh0idYtTlOPD0z V4mIZa8/LxUKXHepyBFAiBFGaV5cCNgcXaJUVZKmJcR6CghnoLUotzMElT5V4ziHIxKwrxqPU BTeDLzSuA2vQI6ggnoCDk2fZAjShIRUlINQPcvfxhlfPEn971pu2cm3dX59PSGw9tYVhO7Kbs 5Es9cXHf5pKpP5Kw1tWUpRmrssYZLDfMTVyTuO81/tFJdckW66LnnyzfdyDjOMVMw6Fqh8e3A GVlt/8PW3Hu7akpQslJr+t11E5NM73SxTly2tOSf09TNgVo+ri52qjFeHoxM/xf8l9NWVmIpz kg01GIuKk4EAC6C+i2uAgAA X-Env-Sender: prvs=930ada366=Andrew.Cooper3@citrix.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1462799749!40390529!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 36065 invoked from network); 9 May 2016 13:15:50 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-7.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 9 May 2016 13:15:50 -0000 X-IronPort-AV: E=Sophos;i="5.24,600,1454976000"; d="scan'208";a="359212797" From: Andrew Cooper To: Xen-devel Date: Mon, 9 May 2016 14:15:39 +0100 Message-ID: <1462799742-15507-2-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1462799742-15507-1-git-send-email-andrew.cooper3@citrix.com> References: <1462799742-15507-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH for-4.7 1/4] x86/hvm: Always return the linear address from hvm_virtual_to_linear_addr() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some callers need the linear address (with appropriate segment base), whether or not the limit or canonical check succeeds. While modifying the function, change the return type to bool_t to match its semantics. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu --- xen/arch/x86/hvm/hvm.c | 37 +++++++++++++++++++++++-------------- xen/include/asm-x86/hvm/hvm.h | 2 +- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 82e2ed1..863d134 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -2411,7 +2411,7 @@ int hvm_set_cr4(unsigned long value, bool_t may_defer) return X86EMUL_EXCEPTION; } -int hvm_virtual_to_linear_addr( +bool_t hvm_virtual_to_linear_addr( enum x86_segment seg, struct segment_register *reg, unsigned long offset, @@ -2421,6 +2421,7 @@ int hvm_virtual_to_linear_addr( unsigned long *linear_addr) { unsigned long addr = offset, last_byte; + bool_t okay = 0; if ( !(current->arch.hvm_vcpu.guest_cr[0] & X86_CR0_PE) ) { @@ -2431,7 +2432,7 @@ int hvm_virtual_to_linear_addr( addr = (uint32_t)(addr + reg->base); last_byte = (uint32_t)addr + bytes - !!bytes; if ( last_byte < addr ) - return 0; + goto out; } else if ( addr_size != 64 ) { @@ -2439,15 +2440,21 @@ int hvm_virtual_to_linear_addr( * COMPATIBILITY MODE: Apply segment checks and add base. */ + /* + * Hardware truncates to 32 bits in compatibility mode. + * It does not truncate to 16 bits in 16-bit address-size mode. + */ + addr = (uint32_t)(addr + reg->base); + switch ( access_type ) { case hvm_access_read: if ( (reg->attr.fields.type & 0xa) == 0x8 ) - return 0; /* execute-only code segment */ + goto out; /* execute-only code segment */ break; case hvm_access_write: if ( (reg->attr.fields.type & 0xa) != 0x2 ) - return 0; /* not a writable data segment */ + goto out; /* not a writable data segment */ break; default: break; @@ -2464,16 +2471,10 @@ int hvm_virtual_to_linear_addr( /* Check first byte and last byte against respective bounds. */ if ( (offset <= reg->limit) || (last_byte < offset) ) - return 0; + goto out; } else if ( (last_byte > reg->limit) || (last_byte < offset) ) - return 0; /* last byte is beyond limit or wraps 0xFFFFFFFF */ - - /* - * Hardware truncates to 32 bits in compatibility mode. - * It does not truncate to 16 bits in 16-bit address-size mode. - */ - addr = (uint32_t)(addr + reg->base); + goto out; /* last byte is beyond limit or wraps 0xFFFFFFFF */ } else { @@ -2487,11 +2488,19 @@ int hvm_virtual_to_linear_addr( last_byte = addr + bytes - !!bytes; if ( !is_canonical_address(addr) || last_byte < addr || !is_canonical_address(last_byte) ) - return 0; + goto out; } + /* All checks ok. */ + okay = 1; + + out: + /* + * Always return the correct linear address, even if a permission check + * failed. The permissions failure is not relevant to some callers. + */ *linear_addr = addr; - return 1; + return okay; } struct hvm_write_map { diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index 7b7ff3f..add6ee8 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -471,7 +471,7 @@ enum hvm_access_type { hvm_access_read, hvm_access_write }; -int hvm_virtual_to_linear_addr( +bool_t hvm_virtual_to_linear_addr( enum x86_segment seg, struct segment_register *reg, unsigned long offset,