All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Isaila <aisaila@bitdefender.com>
To: xen-devel@lists.xen.org
Cc: jun.nakajima@intel.com, kevin.tian@intel.com,
	sstabellini@kernel.org, wei.liu2@citrix.com,
	suravee.suthikulpanit@amd.com, george.dunlap@eu.citrix.com,
	andrew.cooper3@citrix.com, tim@xen.org, paul.durrant@citrix.com,
	Jan Beulich <JBeulich@suse.com>,
	boris.ostrovsky@oracle.com, ian.jackson@eu.citrix.com
Subject: [PATCH v2 1/4] x86/shadow: Use ERR_PTR infrastructure for sh_emulate_map_dest()
Date: Fri,  8 Sep 2017 19:05:33 +0300	[thread overview]
Message-ID: <1504886736-1823-2-git-send-email-aisaila@bitdefender.com> (raw)
In-Reply-To: <1504886736-1823-1-git-send-email-aisaila@bitdefender.com>

From: Andrew Cooper <andrew.cooper3@citrix.com>

sh_emulate_map_dest() predates the introduction of the generic ERR_PTR()
infrastructure, but take the opportunity to avoid opencoding it.

The chosen error constants require need to be negative to work with IS_ERR(),
but no other changes.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

---
CC: Jan Beulich <JBeulich@suse.com>
CC: Tim Deegan <tim@xen.org>

v2:
 * Use ~(long)X86EMUL rather than -X86EMUL so MAPPING_SILENT_FAIL is
   considered an error to IS_ERR()
---
 xen/arch/x86/mm/shadow/multi.c   | 8 ++++----
 xen/arch/x86/mm/shadow/private.h | 7 +++----
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c
index f7efe66..8d4f244 100644
--- a/xen/arch/x86/mm/shadow/multi.c
+++ b/xen/arch/x86/mm/shadow/multi.c
@@ -4754,8 +4754,8 @@ sh_x86_emulate_write(struct vcpu *v, unsigned long vaddr, void *src,
         return X86EMUL_UNHANDLEABLE;
 
     addr = sh_emulate_map_dest(v, vaddr, bytes, sh_ctxt);
-    if ( sh_emulate_map_dest_failed(addr) )
-        return (long)addr;
+    if ( IS_ERR(addr) )
+        return ~PTR_ERR(addr);
 
     paging_lock(v->domain);
     memcpy(addr, src, bytes);
@@ -4796,8 +4796,8 @@ sh_x86_emulate_cmpxchg(struct vcpu *v, unsigned long vaddr,
         return X86EMUL_UNHANDLEABLE;
 
     addr = sh_emulate_map_dest(v, vaddr, bytes, sh_ctxt);
-    if ( sh_emulate_map_dest_failed(addr) )
-        return (long)addr;
+    if ( IS_ERR(addr) )
+        return ~PTR_ERR(addr);
 
     paging_lock(v->domain);
     switch ( bytes )
diff --git a/xen/arch/x86/mm/shadow/private.h b/xen/arch/x86/mm/shadow/private.h
index 46d9bab..6a03370 100644
--- a/xen/arch/x86/mm/shadow/private.h
+++ b/xen/arch/x86/mm/shadow/private.h
@@ -395,10 +395,9 @@ void shadow_unhook_mappings(struct domain *d, mfn_t smfn, int user_only);
 
 /* Returns a mapped pointer to write to, or one of the following error
  * indicators. */
-#define MAPPING_UNHANDLEABLE ((void *)(unsigned long)X86EMUL_UNHANDLEABLE)
-#define MAPPING_EXCEPTION    ((void *)(unsigned long)X86EMUL_EXCEPTION)
-#define MAPPING_SILENT_FAIL  ((void *)(unsigned long)X86EMUL_OKAY)
-#define sh_emulate_map_dest_failed(rc) ((unsigned long)(rc) <= 3)
+#define MAPPING_UNHANDLEABLE ERR_PTR(~(long)X86EMUL_UNHANDLEABLE)
+#define MAPPING_EXCEPTION    ERR_PTR(~(long)X86EMUL_EXCEPTION)
+#define MAPPING_SILENT_FAIL  ERR_PTR(~(long)X86EMUL_OKAY)
 void *sh_emulate_map_dest(struct vcpu *v, unsigned long vaddr,
                           unsigned int bytes, struct sh_emulate_ctxt *sh_ctxt);
 void sh_emulate_unmap_dest(struct vcpu *v, void *addr, unsigned int bytes,
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2017-09-08 16:05 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-08 16:05 [PATCH v2 0/4] Various XSA followups Alexandru Isaila
2017-09-08 16:05 ` Alexandru Isaila [this message]
2017-09-12  9:37   ` [PATCH v2 1/4] x86/shadow: Use ERR_PTR infrastructure for sh_emulate_map_dest() Wei Liu
2017-09-08 16:05 ` [PATCH v2 2/4] x86/hvm: Rename enum hvm_copy_result to hvm_translation_result Alexandru Isaila
2017-09-11 13:27   ` George Dunlap
2017-09-11 13:32     ` Wei Liu
2017-09-11 13:39     ` Andrew Cooper
2017-09-12 10:00       ` George Dunlap
2017-09-18  8:22   ` Tian, Kevin
2017-09-18 13:00   ` Jan Beulich
2017-09-08 16:05 ` [PATCH v2 3/4] x86/hvm: Break out __hvm_copy()'s translation logic Alexandru Isaila
2017-09-18 13:18   ` Jan Beulich
2017-09-08 16:05 ` [PATCH v2 4/4] x86/hvm: Implement hvmemul_write() using real mappings Alexandru Isaila
2017-09-12 14:32   ` Paul Durrant
2017-09-12 14:37     ` Andrew Cooper
2017-09-12 15:05       ` Jan Beulich
2017-09-12 15:06       ` Paul Durrant
2017-09-12 15:09   ` Andrew Cooper
2017-09-12 15:12     ` Paul Durrant
2017-09-18 13:43   ` Jan Beulich
2017-09-18 14:16     ` Alexandru Stefan ISAILA
2017-09-08 20:03 ` [PATCH v2 0/4] Various XSA followups Tim Deegan

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=1504886736-1823-2-git-send-email-aisaila@bitdefender.com \
    --to=aisaila@bitdefender.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=paul.durrant@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.