From patchwork Wed May 11 16:52:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 777302 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4BGrJc7030844 for ; Wed, 11 May 2011 16:53:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757788Ab1EKQxL (ORCPT ); Wed, 11 May 2011 12:53:11 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:40453 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757776Ab1EKQxJ (ORCPT ); Wed, 11 May 2011 12:53:09 -0400 Received: by wwa36 with SMTP id 36so824100wwa.1 for ; Wed, 11 May 2011 09:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=mj86maWhT83dJ4ottBK2nbf1Hak2o+YCb81Ms/jzv+E=; b=idGcfi3/jNrvAOaU0+mpOddpWLN1eQ2f/pl9mnfkVTOjF2muU/UTGCp/TL8L20nLaT dPyLKP/aTs7/r4+9RQygWOhI+tmt9ielMJ/Iik/GfCLRRHBDhprOjmtwjFQPDKhWftiQ WdZ71hE54PSvG0sOkLmez2sH5tNMtMr96aqo0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=qtJfiTaBacuNAY2LhyrBaIha8dpQuXPIl1KNlyL8JQWf/PtJGLvE6F9LLiWnKz9J+A Uo//YD6P/7Ed1RoXp6ekoGy8Va6fOmueowUxW8/YvDa+kWn3JMZnhyrZQtSJIYNpv5TU EZfUk2E8ib0eu23XLqO5t4iY4nmjhytFrIygA= Received: by 10.227.5.210 with SMTP id 18mr6742580wbw.18.1305132787741; Wed, 11 May 2011 09:53:07 -0700 (PDT) Received: from localhost.localdomain ([188.120.134.217]) by mx.google.com with ESMTPS id ca12sm219310wbb.36.2011.05.11.09.53.05 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 11 May 2011 09:53:07 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, prasadjoshi124@gmail.com, avi@redhat.com, gorcunov@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 2/2] kvm tools: Use constants for commonly used mmap flags Date: Wed, 11 May 2011 19:52:57 +0300 Message-Id: <1305132777-9026-2-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 In-Reply-To: <1305132777-9026-1-git-send-email-levinsasha928@gmail.com> References: <1305132777-9026-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 11 May 2011 16:53:20 +0000 (UTC) Signed-off-by: Sasha Levin --- tools/kvm/disk-image.c | 2 +- tools/kvm/include/kvm/util.h | 3 +++ tools/kvm/kvm-cpu.c | 2 +- tools/kvm/kvm.c | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/kvm/disk-image.c b/tools/kvm/disk-image.c index 0bda8db..bddbdb3 100644 --- a/tools/kvm/disk-image.c +++ b/tools/kvm/disk-image.c @@ -39,7 +39,7 @@ struct disk_image *disk_image__new_readonly(int fd, u64 size, struct disk_image_ if (!disk) return NULL; - disk->priv = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_NORESERVE, fd, 0); + disk->priv = mmap(NULL, size, PROT_RW, MAP_PRIVATE | MAP_NORESERVE, fd, 0); if (disk->priv == MAP_FAILED) die("mmap() failed"); return disk; diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h index fc222c3..5f4cbb9 100644 --- a/tools/kvm/include/kvm/util.h +++ b/tools/kvm/include/kvm/util.h @@ -29,6 +29,9 @@ #endif #endif +#define PROT_RW (PROT_READ|PROT_WRITE) +#define MAP_ANON_NORESERVE (MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE) + extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); extern void die_perror(const char *s) NORETURN; extern int error(const char *err, ...) __attribute__((format (printf, 1, 2))); diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c index e69049d..8a27e02 100644 --- a/tools/kvm/kvm-cpu.c +++ b/tools/kvm/kvm-cpu.c @@ -81,7 +81,7 @@ struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id) if (mmap_size < 0) die_perror("KVM_GET_VCPU_MMAP_SIZE ioctl"); - vcpu->kvm_run = mmap(NULL, mmap_size, PROT_READ|PROT_WRITE, MAP_SHARED, vcpu->vcpu_fd, 0); + vcpu->kvm_run = mmap(NULL, mmap_size, PROT_RW, MAP_SHARED, vcpu->vcpu_fd, 0); if (vcpu->kvm_run == MAP_FAILED) die("unable to mmap vcpu fd"); diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index fcb3d58..c69fcc4 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -267,9 +267,9 @@ struct kvm *kvm__init(const char *kvm_dev, unsigned long ram_size) kvm->ram_size = ram_size; if (kvm->ram_size < KVM_32BIT_GAP_START) { - kvm->ram_start = mmap(NULL, ram_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); + kvm->ram_start = mmap(NULL, ram_size, PROT_RW, MAP_ANON_NORESERVE, -1, 0); } else { - kvm->ram_start = mmap(NULL, ram_size + KVM_32BIT_GAP_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); + kvm->ram_start = mmap(NULL, ram_size + KVM_32BIT_GAP_SIZE, PROT_RW, MAP_ANON_NORESERVE, -1, 0); if (kvm->ram_start != MAP_FAILED) { /* * We mprotect the gap (see kvm__init_ram() for details) PROT_NONE so that