lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1354297557-24486-1-git-send-email-js1304@gmail.com>
Date:	Sat,  1 Dec 2012 02:45:57 +0900
From:	Joonsoo Kim <js1304@...il.com>
To:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc:	linux-kernel@...r.kernel.org, devel@...verdev.osuosl.org,
	Android Kernel Team <kernel-team@...roid.com>,
	Joonsoo Kim <js1304@...il.com>,
	John Stultz <john.stultz@...aro.org>,
	Brian Swetland <swetland@...gle.com>,
	Colin Cross <ccross@...roid.com>,
	Arve Hjønnevåg <arve@...roid.com>,
	Dima Zavin <dima@...roid.com>, Robert Love <rlove@...gle.com>
Subject: [RFC PATCH] staging, android, ashmem: invalidate pin/unpin ioctl for private map

Private mapped ashmem doesn't install vm fault handler.
So, do_anonymous_page is called for handling fault in handle_pte_fault().
This type of backed memory isn't related to asma->file which is used by
ashmem shrinker. Shrinking unpinned area for this mapping
will not shrink memory actually.
Although it's memory doesn't actually removed, pin status will
return ASHMEM_WAS_PURGED. So application will re-load content.
This is needless overhead, so invalidate pin/unpin ioctl behavior for
private map.

CC: John Stultz <john.stultz@...aro.org>
CC: Brian Swetland <swetland@...gle.com>
CC: Colin Cross <ccross@...roid.com>
CC: Arve Hjønnevåg <arve@...roid.com>
CC: Dima Zavin <dima@...roid.com>
CC: Robert Love <rlove@...gle.com>
Signed-off-by: Joonsoo Kim <js1304@...il.com>

diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index 634b9ae..2fde9df 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -49,6 +49,7 @@ struct ashmem_area {
 	struct file *file;		 /* the shmem-based backing file */
 	size_t size;			 /* size of the mapping, in bytes */
 	unsigned long prot_mask;	 /* allowed prot bits, as vm_flags */
+	bool shared_mapping;		 /* mapping type */
 };
 
 /*
@@ -327,6 +328,7 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma)
 			fput(asma->file);
 			goto out;
 		}
+		asma->shared_mapping = 1;
 	}
 
 	if (vma->vm_file)
@@ -614,21 +616,35 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd,
 	pgstart = pin.offset / PAGE_SIZE;
 	pgend = pgstart + (pin.len / PAGE_SIZE) - 1;
 
-	mutex_lock(&ashmem_mutex);
+	if (asma->shared_mapping) {
+		mutex_lock(&ashmem_mutex);
 
-	switch (cmd) {
-	case ASHMEM_PIN:
-		ret = ashmem_pin(asma, pgstart, pgend);
-		break;
-	case ASHMEM_UNPIN:
-		ret = ashmem_unpin(asma, pgstart, pgend);
-		break;
-	case ASHMEM_GET_PIN_STATUS:
-		ret = ashmem_get_pin_status(asma, pgstart, pgend);
-		break;
-	}
+		switch (cmd) {
+		case ASHMEM_PIN:
+			ret = ashmem_pin(asma, pgstart, pgend);
+			break;
+		case ASHMEM_UNPIN:
+			ret = ashmem_unpin(asma, pgstart, pgend);
+			break;
+		case ASHMEM_GET_PIN_STATUS:
+			ret = ashmem_get_pin_status(asma, pgstart, pgend);
+			break;
+		}
 
-	mutex_unlock(&ashmem_mutex);
+		mutex_unlock(&ashmem_mutex);
+
+	} else {
+		switch (cmd) {
+		/* if it is private map, pin/unpin have no impact to vm */
+		case ASHMEM_PIN:
+		case ASHMEM_UNPIN:
+			ret = ASHMEM_NOT_PURGED;
+			break;
+		case ASHMEM_GET_PIN_STATUS:
+			ret = ASHMEM_IS_PINNED;
+			break;
+		}
+	}
 
 	return ret;
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ